I found out that structures without any named members (and without any members in particular, as I understood) invoke UB in C. Only GNU GCC supports such structures as an extension. I've tried to create a piece of code which will behave differently when compiled using GCC vs. Clang but with no success. I'm wondering if there is a C program that if you compile it via Clang, it will work differently than if it was compiled using GCC. The opposite option, in a nutshell, is that Clang also supports empty structures but this is not mentioned in documentation.
-
1@KamilCuk: It is one question. The question whether there is a C program with different behavior between GCC and Clang is in the context of a structure with no members. They are asking whether there is a program that illustrates that GCC defines the behavior of a structure with no members and Clang either does not or defines it differently. – Eric Postpischil Nov 01 '22 at 10:36
-
The question you should ask yourself (and the loose cannons who invent all these crazy GNU extensions): _Why_ would you ever want an empty struct declaration and what problem is that supposed to solve? – Lundin Nov 01 '22 at 10:41
-
1"The opposite option, in a nutshell, is that Clang also supports empty structures but this is not mentioned in documentation." Well that's likely it. There's a fierce competition between clang and gcc regarding who has the worst documentation. I would expect to find clang documentation about gcc extensions here: https://clang.llvm.org/docs/UsersManual.html#extensions-supported-by-clang or here https://clang.llvm.org/docs/LanguageExtensions.html#introduction But I can't find it. My guess is that the documentation was stored inside an empty struct... – Lundin Nov 01 '22 at 10:53
2 Answers
Literally the only thing I could find in clang's documentation is some info about a warning -Wgnu-empty-struct
, which will be activated in -pedantic
mode. So the compiler clearly supports GNU empty structs.
As for where to find the clang documentation regarding how empty structs should be used, what they are good for and under which language standards they are valid, I have no idea.

- 195,001
- 40
- 254
- 396
For completeness, as Lundin wrote, empty structs are supported in Clang.
I'm wondering if there is a C program that if you compile it via Clang, it will work differently than if it was compiled using GCC. The opposite option, in a nutshell, is that Clang also supports empty structures but this is not mentioned in documentation.
Undefined behavior means that it's undefined. The clang compiler is allowed to produce binary code as gcc even if it does not support empty structs. Be very careful to draw conclusions strictly from behavior.

- 30,332
- 17
- 55
- 95