在gcc中执行C ++ 98标准 [英] Enforcing the C++98 standard in gcc
问题描述
我有一个学校作业,应该使用符合C ++ 98的代码编写.如何强制g++
仅接受遵循此标准的代码? -std=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?
推荐答案
每 GCC有关标准的文档 :
原始ISO C ++标准已发布为ISO标准(ISO/IEC 14882:1998),并于2003年发布了技术勘误(ISO/IEC 14882:2003)进行了修订.这些标准分别称为C ++ 98和C ++ 03. GCC实现了大多数C ++ 98(导出是一个明显的例外)以及C ++ 03中的大多数更改.要在GCC中选择此标准,请使用选项-ansi,-std = c ++ 98或-std = c ++ 03;要获得标准要求的所有诊断,还应该指定-pedantic(如果希望它们是错误而不是警告,则应指定-pedantic-errors).
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).
因此,如果您确实要确保符合标准,则应指定-std=c++98 -pedantic
.
Therefore, you should specify -std=c++98 -pedantic
if you really want to ensure standards compliance.
这篇关于在gcc中执行C ++ 98标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!