Init string var

Moderator: Benj

Post Reply
JCMB
Posts: 22
Joined: Wed Feb 08, 2006 3:15 pm
Location: St Etienne, France
Been thanked: 1 time
Contact:

Init string var

Post 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.

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Init string var

Post 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

Post Reply