77
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
this post was submitted on 09 Nov 2025
77 points (96.4% liked)
Linux
13188 readers
268 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
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
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.