what's this syntax ?

Michael Gong gonwg@hotmail.com
Wed Mar 28 14:33:00 GMT 2007


Hi, John,

Thanks for reply and the information is very helpful.

However, to clarify a bit, I don't think it's a valid C99 code. 
According to gcc manual, 
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Designated-Inits.html#Designated-Inits
..

To initialize a range of elements to the same value, write `[first ... 
last] = value'. This is a GNU extension. For example,

     int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };
..



Thanks.



Mike



----- Original Message ----- 
From: "John Love-Jensen" <eljay@adobe.com>
To: "Michael Gong" <gonwg@hotmail.com>; "MSX to GCC" 
<gcc-help@gcc.gnu.org>
Sent: Wednesday, March 28, 2007 9:19 AM
Subject: Re: what's this syntax ?


> Hi Michael,
>
> I think the '...' is called an ellipsis in the array initializer.
>
> So you can do something like:
>
> int array[10] = { [4] = 9, [1 ... 2] = 88, [7 ... 9] = 1 };
>
> It's valid C99 code.
>
> IIRC, it's *NOT* valid C90 or C++98 code.  (I'm not sure if GCC 
> provides
> convenience extensions that you may have to disable in a C90 or C++98
> environment.)
>
> You may find this output of interest:
>
> gcc -S test.c
> cat test.s
>
> HTH,
> --Eljay
>
> 



More information about the Gcc-help mailing list