3

I programmed C++ for a while. Now I want to program a ANSI C program, don't want any "C++ only" feature in the code. I'm using cygwin 64 bit with gcc installed. Are there any settings to let gcc prompt compiler error if encounter C++ features? E.g. the stl.

Thank you in advance.

4

1 回答 1

7

以下内容来自gcc 文档

最初的 ANSI C 标准 (X3.159-1989) 于 1989 年获得批准并于 1990 年发布。该标准于 1990 年晚些时候被批准为 ISO 标准 (ISO/IEC 9899:1990)。这些出版物之间没有技术差异,尽管 ANSI 标准的部分被重新编号并成为 ISO 标准中的条款。从批准之日起,该标准的两种形式通常称为 C89,有时也称为 C90。ANSI 标准,但不是 ISO 标准,也带有一个基本原理文档。要在 GCC 中选择此标准,请使用选项 -ansi、-std=c90 或 -std=iso9899:1990 之一;要获得标准所需的所有诊断,您还应该指定 -pedantic(或 -pedantic-errors,如果您希望它们是错误而不是警告)。

因此,使用以下标志进行编译:

gcc myfile.c -ansi -pedantic-errors

请注意 -ansi 和 -std=c90 是同义词。有关选项的完整列表,请参阅控制 C 方言的选项

于 2013-07-31T23:06:42.183 回答