Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforcing the C++98 standard in gcc

Tags:

c++

gcc

c++98

I have a school assignment that should be written in C++98-compliant code. How can I force g++ to accept only code that follows this standard? Will -std=c++98 do the trick or do I need to add additional flags?

like image 764
Pieter Avatar asked Sep 26 '12 16:09

Pieter


1 Answers

Per GCC's documentation on standards:

The original ISO C++ standard was published as the ISO standard (ISO/IEC 14882:1998) and amended by a Technical Corrigenda published in 2003 (ISO/IEC 14882:2003). These standards are referred to as C++98 and C++03, respectively. GCC implements the majority of C++98 (export is a notable exception) and most of the changes in C++03. To select this standard in GCC, use one of the options -ansi, -std=c++98, or -std=c++03; to obtain all the diagnostics required by the standard, you should also specify -pedantic (or -pedantic-errors if you want them to be errors rather than warnings).

Therefore, you should specify -std=c++98 -pedantic if you really want to ensure standards compliance.

like image 188
nneonneo Avatar answered Oct 05 '22 17:10

nneonneo