简体   繁体   English

在gcc中执行C ++ 98标准

[英]Enforcing the C++98 standard in gcc

I have a school assignment that should be written in C++98-compliant code. 我有一个学校作业,应该用符合C ++ 98的代码编写。 How can I force g++ to accept only code that follows this standard? 如何强制g++只接受遵循此标准的代码? Will -std=c++98 do the trick or do I need to add additional flags? 请问-std=c++98可以解决这个问题,还是需要添加额外的标志?

Per GCC's documentation on standards : 根据GCC的标准文件

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). 最初的ISO C ++标准作为ISO标准(ISO / IEC 14882:1998)公布,并由2003年出版的技术勘误表(ISO / IEC 14882:2003)进行了修订。 These standards are referred to as C++98 and C++03, respectively. 这些标准分别称为C ++ 98和C ++ 03。 GCC implements the majority of C++98 (export is a notable exception) and most of the changes in C++03. GCC实现了大部分C ++ 98(导出是一个值得注意的例外)和C ++ 03中的大多数更改。 To select this standard in GCC, use one of the options -ansi, -std=c++98, or -std=c++03; 要在GCC中选择此标准,请使用以下选项之一-ansi,-std = c ++ 98或-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). 要获得标准所需的所有诊断,您还应指定-pedantic(或-pedantic-errors,如果您希望它们是错误而不是警告)。

Therefore, you should specify -std=c++98 -pedantic if you really want to ensure standards compliance. 因此,如果您确实希望确保符合标准,则应指定-std=c++98 -pedantic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM