Page 1 of 1

Init string var

Posted: Wed Feb 29, 2012 10:31 am
by JCMB
J create a var MyVar[12] and init it in the project expolrer as "1234567890AB"
Compile give the error: "Too many initializers"
If J change MyVar[12] to MyVar[13] or if J init it with "" compiling is OK.

Re: Init string var

Posted: Wed Feb 29, 2012 12:50 pm
by JonnyW
Hello.

C will automatically add a null terminator to any literal you give it. So your string is actually: "1234567890AB\0"

Flowcode string concatenations do not have this limitation, but assignment through intialisers is done with the C compiler. If you want that string as an initialiser, you will have to create it as a 13-element value.

On the other hand, if you do not wish to change the contents of the string once it is initialised, you can create it as a constant, which can be any length.

Jonny