6 ms·
Anybody know what the: int needfid[] = { [Tversion] 0, [Tflush] 0, [Tauth] 0, syntax means? Is this some Plan 9 extension, or is it just something I've n
by jstanley 13y ago
Anybody know what the:
int needfid[] = {
[Tversion] 0,
[Tflush] 0,
[Tauth] 0,
syntax means? Is this some Plan 9 extension, or is it just something I've never encountered?
EDIT: I guess the value in the []'s is the array index to set the value of.
- _pmf_ 13y ago> Is this some Plan 9 extension, or is it just something I've never encountered? It's C99 (I also only saw it in C99 articles, never in production code). See http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Designated-Inits.html http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Designated-Inits...
- pdw 13y agoIt's heavily used in the Linux kernel and in the Linux world in general. But Visual Studio doesn't support it, so projects that target Windows pretty much have to avoid it.
- pdw 13y agoA variation of this syntax was standardized in C99: int needfid[] = { [Tversion] = 0, [Tflush] = 0, It works for structs too: struct blah needfid = { .version = 0, .flush = 0,
- glurgh 13y agoThat's right, it's a designated initializer, except the standard c99 way requires an =. gcc didn't/doesn't but that's nonstandard. So it is an extension, just not a plan9 one - a gcc-ism. clang's error/warning, as usual, is very helpful so it's worth it just to try clang when running into weirdness like that: warning: use of GNU 'missing =' extension in designator [-Wgnu-designator]
- aap_ 13y agoWell, it is a Plan 9 extension. You made it sound like it was only a gcc extension.
- glurgh 13y agoYou're right, it's described in 3.5 of http://plan9.bell-labs.com/sys/doc/compiler.html http://plan9.bell-labs.com/sys/doc/compiler.html It seems like it was contemporaneous with the proposed c90 extension and also supported the = except optionally. But it was definitely something in the plan 9 compiler rather than only a gcc thing.
- Mr_T_ 13y agoSee "3.5 Initialization indexes": http://plan9.bell-labs.com/sys/doc/compiler.html http://plan9.bell-labs.com/sys/doc/compiler.html