Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a bad idea to use GCC's -fms-extensions?

Tags:

c

gcc

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?

like image 836
Alexis King Avatar asked Dec 31 '12 20:12

Alexis King


People also ask

Should I use latest GCC?

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.

Should I use Clang instead of GCC?

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.

Is GCC compiler good?

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).

Which is better GCC or G ++?

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.


2 Answers

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.

like image 153
R.. GitHub STOP HELPING ICE Avatar answered Sep 18 '22 11:09

R.. GitHub STOP HELPING ICE


If you are looking for compatibility, it is never a good idea to set lax compiler options, stricter - the more portable

like image 41
Ofir Avatar answered Sep 20 '22 11:09

Ofir