73
this post was submitted on 09 Nov 2025
73 points (96.2% liked)
Linux
10210 readers
855 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
Nice, thank you
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.
Does that really have the same results as the example scenario I described? How would you even access the unnamed struct, since it is unnamed?
The same way you did, via the name of the member:
my_test.test2.b = 'x';The unnamed struct provides the type for a member named
test2. Doing it this way saves you the trouble of defining the struct externally and giving it a name. It's identical to this, except in this example you can reuse the struct definition:Basically the extensions are useful sometimes. Note that they have nothing to do with Microsoft other than being invented by them.
Old languages should be able to learn new tricks.
Some software require it sadly
The "extend" phase of EEE.