77
this post was submitted on 09 Nov 2025
77 points (96.4% liked)
Linux
10091 readers
700 users here now
A community for everything relating to the GNU/Linux operating system (except the memes!)
Also, check out:
Original icon base courtesy of lewing@isc.tamu.edu and The GIMP
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Why?
I'm sitting around doing IT shit waiting things to download/backup/install/etc and have nothing better to do, so here's an AI-free explanation with code samples:
It's basically just a code style thing. Standard C allows you to declare unnamed structs/unions within other structs/unions. They must be unnamed, so it'd look like this:
Which is fine, but the
-fms-extensionsflag enables you to do the same thing with named structs. For example:without
-fms-extensions, the above will compile, but won't do what you might assume.bandcwill be members of structtest2, nottest. So something like this won't compile:But with the flag, not only does it work, it also lets you do some convenient things like this:
That is, you can reuse an existing struct definition, which gives you a nice little tool to organize your code.
Source: https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html
What's the point of this? If you have a struct within a struct, you probably want them to nest. The
-fms-extensionswill un-nest them, which is not what you mean.You can already do that in standard C like this:
I can't think of any particular reason why you'd want an unnamed struct inside a struct, but you definitely would want to be able to have an unnamed struct inside a union. I suspect the struct-inside-struct thing can become useful in some scenarios involving unions.
If this is so convenient, why wasn't it made a part of a newer C standard?
It's not that convenient. I can't even think of a situation where this would be useful for structs, only unions. And in the case of unions, you usually want to keep them as small as possible (or better yet, avoid them altogether).
But besides that, C is a language that tends to prefer minimalism. Using macros, you can accomplish a similar thing already, even if it's not as nice.
Nice, thank you
Basically the extensions are useful sometimes. Note that they have nothing to do with Microsoft other than being invented by them.
The "extend" phase of EEE.
Some software require it sadly
Old languages should be able to learn new tricks.