gpt4 book ai didi

c++ - 如何确保我的代码是 ansi C,不涉及 C++。是否可以设置像gcc这样的编译器在遇到C++的特性时提示错误?

转载 作者:太空狗 更新时间:2023-10-29 20:26:53 26 4
gpt4 key购买 nike

我编写了一段时间的 C++。现在我想编写一个 ANSI C 程序,不想在代码中使用任何“仅 C++”功能。我正在使用安装了 gcc 的 cygwin 64 位。有没有设置让gcc在遇到C++特性时提示编译错误?例如。 STL.

提前谢谢你。

最佳答案

以下摘自gcc documentation :

The original ANSI C standard (X3.159-1989) was ratified in 1989 and published in 1990. This standard was ratified as an ISO standard (ISO/IEC 9899:1990) later in 1990. There were no technical differences between these publications, although the sections of the ANSI standard were renumbered and became clauses in the ISO standard. This standard, in both its forms, is commonly known as C89, or occasionally as C90, from the dates of ratification. The ANSI standard, but not the ISO standard, also came with a Rationale document. To select this standard in GCC, use one of the options -ansi, -std=c90 or -std=iso9899:1990; 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).

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

gcc myfile.c -ansi -pedantic-errors

请注意 -ansi 和 -std=c90 是同义词。有关选项的完整列表,请参阅 Options Controlling C Dialect .

关于c++ - 如何确保我的代码是 ansi C,不涉及 C++。是否可以设置像gcc这样的编译器在遇到C++的特性时提示错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17982433/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com