LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Equivalent of std=c99 for C++ ? (https://www.linuxquestions.org/questions/programming-9/equivalent-of-std%3Dc99-for-c-782972/)

gnashley 01-18-2010 08:59 AM

Equivalent of std=c99 for C++ ?
 
Is there a compiler compatibility flag for C++ like -std=c99 ? Or is there some other way to get new g++ compilers to not choke on old code?

ForzaItalia2006 01-18-2010 04:21 PM

Quote:

Originally Posted by gnashley (Post 3830858)
Is there a compiler compatibility flag for C++ like -std=c99 ? Or is there some other way to get new g++ compilers to not choke on old code?

Yes, C++ compiler uses the same flag like the C compiler, so just use the -std= option with one of the following values:
  • c++98: The 1998 ISO C++ standard plus amendments. Same as -ansi for C++ code.
  • gnu++98: GNU dialect of -std=c++98. This is the default for C++ code.
  • c++0x: The working draft of the upcoming ISO C++0x standard. This option enables experimental features that are likely to be included in C++0x. The working draft is constantly changing, and any feature that is enabled by this flag may be removed from future versions of GCC if it is not part of the C++0x standard.
  • gnu++0x: GNU dialect of -std=c++0x. This option enables experimental features that may be removed in future versions of GCC.

- Andi -

gnashley 01-19-2010 01:21 AM

Ah, thanks very much. I'm pretty sure I did try std=c++99 and got an error about unrecognized option, so I'll probably have to rebuild the compiler to enable the support for it.

ForzaItalia2006 01-19-2010 09:39 AM

Quote:

Originally Posted by gnashley (Post 3831779)
Ah, thanks very much. I'm pretty sure I did try std=c++99 and got an error about unrecognized option, so I'll probably have to rebuild the compiler to enable the support for it.

What version of gcc/g++ are you using? (gcc -v)

- Andi -

gnashley 01-19-2010 11:00 AM

Well, various. My main compiler right now is 4.4.2, but I have 4.3.2 and 4.2.1. When I have something really old to compile, I usually break down and use 3.4.6 which I have st up as an alternative compiler. 4.3.2 and 4.2.1 are both candidates for my main compiler -I have my own home-grown system so I can settle on any one of them in the end, thoguh 4.4.2 would be the best bet since I am using glibc-2.11.1. I pretty sure that gcc-4.3.2 supports the --enable-c99 configuration option, but do I need to pass --enable-c++99 as well?

Is using the -ansi compiler option comparable, or is that only for C?

ForzaItalia2006 01-20-2010 05:09 PM

Quote:

Originally Posted by gnashley (Post 3832347)
Well, various. My main compiler right now is 4.4.2

Okay, 4.4.2 looks quite recent ;-)

Quote:

Originally Posted by gnashley (Post 3832347)
I pretty sure that gcc-4.3.2 supports the --enable-c99 configuration option, but do I need to pass --enable-c++99 as well?

I don't know about these options - which doesn't mean they don't exist - but I can't find any indications in 4.4.2 at least that the -std options depend on the configure input. As far as I know, the -std=* options should be valid for the default configuration of gcc/g++.

Quote:

Originally Posted by gnashley (Post 3832347)
Is using the -ansi compiler option comparable, or is that only for C?

Here's the comment from the man page:

-ansi: In C mode, this is equivalent to -std=c89. In C++ mode, it is equivalent to -std=c++98.

- Andi -


All times are GMT -5. The time now is 07:06 PM.