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

标签 c c89 visual-c++-2015

我试图让 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/

相关文章:

C 模数和余数

c++ - C99 的所有功能是否也在 C++ 中?

c - 使用符合 C89 标准的 M_PI

c - 我如何知道 cl.exe 应用的是 c89 还是 c99?

c++ - 为什么 std::thread 在其构造函数中等待?

c++ - CreateFile 异常安全吗?

c - 什么时候将静态函数定义放在 C 的头文件中?

c++ - 等待另一个 child 的 child

c - 扫描到二维数组,然后将其传递给函数 - C