gpt4 book ai didi

c - 在 Visual Studio 2015 中强制执行 ANSI C 标准

转载 作者:行者123 更新时间:2023-12-01 13:38:52 25 4
gpt4 key购买 nike

我试图让 Visual Studio 在编译项目时强制执行 ANSI C 标准,但我无法让它工作。
有小费吗?
我已经阅读了所有教程,启用了/Za 选项,并将我的文件命名为 .c(不是 .cpp)。但是,以下程序仍然成功构建:

#include <stdio.h>
void main(void)
{
for (int i = 0; i < 10; i++)
{
}
int f = 0;
}

但不应该。要尊重 ANSI C 标准,就必须像这样:
#include <stdio.h>
void main(void)
{
int i;
int f = 0;
for (i = 0; i < 10; i++)
{
}
}

我想要相当于 GCC 选项“ -ansi ”和“ -Wpedantic ”。
这在VS中甚至可能吗?

最佳答案

来自 this page , MSVC 2015 似乎只支持 C99:

C99 Conformance Visual Studio 2015 fully implements the C99 Standard Library, with the exception of any library features that depend on compiler features not yet supported by the Visual C++ compiler (for example, <tgmath.h> is not implemented).



该页面上的任何地方都没有提及 C89 兼容性。

/Za switch仅禁用 Microsoft 特定扩展:

The Visual C++ compiler offers a number of features beyond those specified in either the ANSI C89, ISO C99, or ISO C++ standards. These features are known collectively as Microsoft extensions to C and C++. These extensions are available by default, and not available when the /Za option is specified. For more information about specific extensions, see Microsoft Extensions to C and C++.



如果非 Microsoft 特定扩展是它支持的官方 C 标准(如 C99)的一部分,它不会禁用非 Microsoft 特定扩展。

关于c - 在 Visual Studio 2015 中强制执行 ANSI C 标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42043078/

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