How do I get the anonymous struct/union behaviour activated by -fplan9-extensions
in GCC to work in Clang?
I'm getting errors assigning to members of anonymous when using designated initializers, and I'm not getting the free casting to the type of an anonymous member. Both these work under GCC with the aforementioned extension activated.
typedef struct {int hi;} Embedded;
typedef struct {Embedded;} Encapsulating;
Encapsulating poo = {.hi = 3;};
error: field designator 'hi' does not refer to any field in type 'Encapsulating'
void takes_embedded(Embedded *m);
takes_embedded(&poo);
warning: incompatible pointer types passing 'Encapsuating *' to parameter of type 'Embedded *'
GCC supports more traditional languages than Clang and LLVM, such as Ada, Fortran, and Go. GCC supports more less-popular architectures, and supported RISC-V earlier than Clang and LLVM. GCC supports more language extensions and more assembly language features than Clang and LLVM.
LLVM is a backend compiler meant to build compilers on top of it. It deals with optimizations and production of code adapted to the target architecture. CLang is a front end which parses C, C++ and Objective C code and translates it into a representation suitable for LLVM.
GCC does not have this. GCC's PCH mechanism (which is just a dump of the compiler memory image) is related, but is architecturally only able to read the dump back into the exact same executable as the one that produced it (it is not a structured format). Clang is much faster and uses far less memory than GCC.
In the end, Apple chose to develop Clang, a new compiler front end that supports C, Objective-C and C++.
Here's how to get the -fplan9-extensions
functionality in Clang:
Some of the -fplan9-extensions
functionality (the struct { Embedded; }
part) is already available under the -fms-extensions
argument, but designated initializers for such anonymous members are not supported. The other part is similar in spirit to GCC's __attribute__((transparent_union))
functionality, which Clang already supports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With