News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Array initialization

Started by aj, June 20, 2009, 04:50:37 PM

Previous topic - Next topic

aj

char *txt[1] = {
[0] "asdf",
};


This works in Pelles C - should it?

AlexN

Quote from: aj on June 20, 2009, 04:50:37 PM
char *txt[1] = {
[0] "asdf",
};


This works in Pelles C - should it?

I would say YES!  ;)

You define an array of strings with one member and this member points to "asdf".   :)
best regards
Alex ;)

nicolas.sitbon

it souldn't.
at least, = operator is missing :
char *txt[1] = {
[0] = "asdf",
};

but better is
char const *txt[] = {
[0] = "asdf",
};


Let's look the standard:
Quote6.7.8 Initialization
Syntax
1    initializer:
          assignment-expression
          { initializer-list }
          { initializer-list ,}
     initializer-list:
          designationopt initializer
          initializer-list , designationopt initializer
     designation:
          designator-list =
     designator-list:
          designator
          designator-list designator
     designator:
          [ constant-expression ]
          . identifier

Pelle

Right now the compiler will no insist on the missing '=' (IIRC for compatibility reasons), but a warning should be issued (in standard mode at least).
/Pelle