fb39ca4 / picoc

Automatically exported from code.google.com/p/picoc
0 stars 0 forks source link

array declaration/initialization not supported at all #131

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
PicoC does not support array declarations as in the example:

char *names[] = {
        [3] = "foo", 
        [1] = "bar", 
        [0] = "man"
};

And the following code should iterate the loop 3 times:

int i;
for (i=0; i<sizeof(names)/sizeof(char); i++)
{
    puts(names[i]);
}

that should output:

man
bar

and exit the loop while it hits NULL at names[2] ;)

Original issue reported on code.google.com by belli...@asiotec.org on 22 Feb 2011 at 11:07

GoogleCodeExporter commented 8 years ago
Interesting. Is that even legal C?

Original comment by zik.sale...@gmail.com on 22 Feb 2011 at 11:12

GoogleCodeExporter commented 8 years ago
I just checked it with gcc -pedantic. It says:

"warning: ISO C90 forbids specifying subobject to initialize"

Original comment by zik.sale...@gmail.com on 22 Feb 2011 at 11:20

GoogleCodeExporter commented 8 years ago
It seems it has been implemented later, most compilers supports it. I got no 
idea if it was implemented in ANSI C or later in ISO C. However i though it 
could be nice to see this in picoc.

Original comment by belli...@asiotec.org on 23 Feb 2011 at 11:19

GoogleCodeExporter commented 8 years ago
Designated Initialisers are a C99 feature, see e.g.

http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

If the picoc target is still C90, this would be an extension.

Original comment by DrZip...@gmail.com on 13 Nov 2011 at 4:33

GoogleCodeExporter commented 8 years ago
A simpler example of the issue:
int values[] = {1, 2, 3};
Error message: operator not expected here

Original comment by christop...@gmail.com on 29 Aug 2012 at 2:14

GoogleCodeExporter commented 8 years ago
Currently implementing array initialisers. Not going to implement designated 
initialisers.

Original comment by zik.sale...@gmail.com on 1 Sep 2012 at 7:25

GoogleCodeExporter commented 8 years ago
Now supports array initialisers with the following forms:

    int fred[3] = { 12, 34, 56 };
    double joe[] = { 23.4, 56.7, 89.0 };
    double jaz[] = { 23.4, 56.7, 89.0, };

Original comment by zik.sale...@gmail.com on 6 Sep 2012 at 12:10