CodyIT@programming.dev to Linux@lemmy.ml · 2 days agoThe Linux Kernel Looks To "Bite The Bullet" In Enabling Microsoft C Extensionswww.phoronix.comexternal-linkmessage-square13fedilinkarrow-up152arrow-down117cross-posted to: [email protected]
arrow-up135arrow-down1external-linkThe Linux Kernel Looks To "Bite The Bullet" In Enabling Microsoft C Extensionswww.phoronix.comCodyIT@programming.dev to Linux@lemmy.ml · 2 days agomessage-square13fedilinkcross-posted to: [email protected]
minus-squareObin@feddit.orglinkfedilinkarrow-up20·edit-22 days agoYou mean ‘unnamed’ is what’s confusing you? Normally you can do anonymous struct/union members or struct struct/union members that are tagged structs but not anonymous. I.e. in standard C you’d have to do either: struct foo { int baz; }; struct bar { struct foo foo; }; ... struct bar data; data.foo.baz = 0; or: struct bar { struct { int baz; } foo; }; ... struct bar data; data.baz = 0; but to do the following, you’d need the extension: struct foo { int baz; }; struct bar { struct foo; }; ... struct bar data; data.baz = 0;
minus-squaremina86@lemmy.wtflinkfedilinkEnglisharrow-up8·edit-21 day agoMinor correction: Unnamed structs and unions (so your second example) are not part of C. They are GNU extensions.
minus-squareMinekPo1 [it/she]@lemmygrad.mllinkfedilinkarrow-up3·edit-22 days ago“ANSI C” by Kernighan and Ritchie disagrees , including that syntax (note : retranslation from Polish as that’s the language my copy is in) : A8.3 […] struct-union-specifier: , union-struct identifier ₒₚₜ { compound-declaration-list } , union-struct identifier […] Specifiers of structures or unions with [a compound declaration] list, but with no label [identifier], creates a unique type; it may only be referred to in the declaration in which it is part.
minus-squaremina86@lemmy.wtflinkfedilinkEnglisharrow-up1·1 day agoYes, but I was talking about field name, not struct tag. And up to C99 my comment was correct.
minus-squareObin@feddit.orglinkfedilinkarrow-up3·edit-22 days agoUnless I’m misunderstanding something, I’m pretty sure they’ve been standardized in C11. Also mentioned here.
You mean ‘unnamed’ is what’s confusing you?
Normally you can do anonymous struct/union members or struct struct/union members that are tagged structs but not anonymous.
I.e. in standard C you’d have to do either:
struct foo { int baz; }; struct bar { struct foo foo; }; ... struct bar data; data.foo.baz = 0;or:
struct bar { struct { int baz; } foo; }; ... struct bar data; data.baz = 0;but to do the following, you’d need the extension:
struct foo { int baz; }; struct bar { struct foo; }; ... struct bar data; data.baz = 0;Minor correction: Unnamed structs and unions (so your second example) are not part of C. They are GNU extensions.“ANSI C” by Kernighan and Ritchie disagrees , including that syntax (note : retranslation from Polish as that’s the language my copy is in) :
Yes, but I was talking about field name, not struct tag. And up to C99 my comment was correct.
Unless I’m misunderstanding something, I’m pretty sure they’ve been standardized in C11. Also mentioned here.
You appear to be correct.