A co-worker of mine was just showing me a C construct that neither of us
have ever seen before.
Here it is:
int myArray [10] = { [0 … 9] = 47 };
This is a slightly simplified version of what we actually saw. What we saw
was initializing an array of structures of interrupt handlers vectors. It
came from a Linux system. Now it’s fairly obvious what the intent is. And
we’re all wanted to do something like this before. But I didn’t think that
this was legal C. For the record, it does compile under the Linux gcc but
not under the QNX Watcom compiler.
Does anyone know if this is a new language feature or just some gcc
extension to the language and when it was introduced?
: A co-worker of mine was just showing me a C construct that neither of us
: have ever seen before.
: Here it is:
: int myArray [10] = { [0 … 9] = 47 };
: This is a slightly simplified version of what we actually saw. What we saw
: was initializing an array of structures of interrupt handlers vectors. It
: came from a Linux system. Now it’s fairly obvious what the intent is. And
: we’re all wanted to do something like this before. But I didn’t think that
: this was legal C. For the record, it does compile under the Linux gcc but
This is not ANSI C (C89) no. And I do not even think C99 is allowing
this, but did not check.
: not under the QNX Watcom compiler.
You could do
int myArray [10] = {47, 47, 47, 47, 47, 47, 47, 47, 47, 47};
, looks cumbersome he !.
: Does anyone know if this is a new language feature or just some gcc
: extension to the language and when it was introduced?
This is a gcc extension, see the gcc manual for other “goodies”.
I believe it was there in gcc-2.8.x and going further then gcc-2.8.x
is not worth the effort. Although the Linux kernel could only
be compile with 2.7.2.x only for along time, and constructs like
this was part of it(with other gcc extensions). So 2.7.2.x look
like a safe bet too.
–
au revoir, alain
Aussi haut que l’on soit assis, on n’est toujours assis que sur son cul !!!
// I have a script that generated it up to 160 and then
256,512,1024,2048,4096,8192
// if you need more just tell me and I can generate it up to 1,048,576 if
you want =)
A co-worker of mine was just showing me a C construct that neither of us
have ever seen before.
Here it is:
int myArray [10] = { [0 … 9] = 47 };
This is a slightly simplified version of what we actually saw. What we
saw
was initializing an array of structures of interrupt handlers vectors. It
came from a Linux system. Now it’s fairly obvious what the intent is.
And
we’re all wanted to do something like this before. But I didn’t think
that
this was legal C. For the record, it does compile under the Linux gcc but
not under the QNX Watcom compiler.
Does anyone know if this is a new language feature or just some gcc
extension to the language and when it was introduced?