Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a populated array of strings
(01-26-2021, 01:07 AM)patters Wrote: Hi Boriel,

I notice that I cannot do the following:
DIM stringArray(2) AS STRING => {"apples", "oranges", "pears"}

The compiler returns "error: Initializer expression is not constant."

Digging on this forum reveals a post from 2009, in which you state this is not possible because string lengths are dynamic. Is this still the case? As you posted in that thread, it ought to be simple to just have the compiler run a bunch of individual LET assignments, but it's a bit ugly to have to type them out.


Strings are not "normal values", but a dynamic structure (If you're used to C, it's implemented as a pointer to an array of bytes, etc...). This requires heap handling and many other operations behind scenes. Other than "syntax sugar", this would not provide memory or speed benefits, and requires a lot of effort, so this feature is "on hold", to prioritize other ones.

Remember you can use READ and DATA to populate an array with strings, as you would do in Sinclair BASIC.

DIM stringArray(2) AS STRING
FOR i = 0 TO UBOUND(stringArray, 1)
  READ stringArray(i)

DATA "apples", "oranges", "pears", stringArray(0) + " and " + stringArray(2), FuncCall(stringArray(1)) + "suffix"

Messages In This Thread
RE: Creating a populated array of strings - by boriel - 01-26-2021, 08:03 AM

Forum Jump:

Users browsing this thread: 1 Guest(s)