Is it a good idea to use GCC -fms extensions?

GCC has the -fms-extensions option, which allows you to use anonymous structure elements:

 struct a { int x; } struct b { int y; struct a; } 

This allows you to access element x in struct b simply by using bx . This is very useful, but it seems to be a Microsoft extension that is emulated by GCC.

Will using this option make my code less portable or consider it "safe"?

+8
c gcc
source share
3 answers

If you are looking for compatibility, it is never recommended to set the lax compiler options, more stringent - more portable

+13
source share

Given that a function that seems equivalent, called anonymous structures and unions, was added to C in 2011 by the standard standard (C11), I would say that it is not such a bad idea to use this function. MS compilers support it, compatible GCC and GNU C compilers support it if requested, and newer compilers that conform to the modern standard support it.

+6
source share

The -fms-extensions flag is used to "Accept some custom constructs used in Microsoft header files." GCC is powerful because it is built for different standards, so I don’t think it’s a bad idea to use this under the right circumstances.

+4
source share

All Articles