GCC has an option, -fms-extensions
, which permits the use of anonymous struct members:
struct a {
int x;
}
struct b {
int y;
struct a;
}
This allows access of an x
element in struct b
simply by using b.x
. This is extremely useful, but it would seem that it is a Microsoft extension being emulated by GCC.
Will using this option make my code less portable, or is it considered "safe" to use?
In general, it is a good idea to use the latest g++ compiler. However, in a few occasions I have had problems with the libraries that I use. For example, the version 4.5 of g++ broke the version of boost::xpressive that I was using. Or better said, it revealed something broken in the library.
Pro's of clang vs GCC: The Clang ASTs and design are intended to be easily understandable by anyone who is familiar with the languages involved and who has a basic understanding of how a compiler works. GCC has a very old codebase which presents a steep learning curve to new developers.
GCC has always performed well as a standard compiler in the open source community. However, Apple Inc. has its own requirements for compilation tools. On the one hand, Apple Inc. added many new features for the Objective-C language (or even, later, the C language).
gcc vs g++ All stock C programs can be made to compile under g++ and without using any C++ libraries or templates. Our experience is that g++ is a better compiler than gcc.
Considering that a feature that seems equivalent, called anonymous structures and unions, was added to C in the 2011 edition of the standard (C11), I would say it's not such a bad idea to use this feature. MS compilers support it, GCC and "GNU C" compatible compilers support it if asked to, and new compilers conforming to the modern standard support it.
If you are looking for compatibility, it is never a good idea to set lax compiler options, stricter - the more portable
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