简体   繁体   English

在Visual Studio 2015中实施ANSI C标准

[英]Enforce ANSI C Standard in Visual Studio 2015

I am trying to get Visual Studio to enforce the ANSI C standard when compiling a project, but I can't get it to work. 我正在尝试让Visual Studio在编译项目时强制执行A​​NSI C标准,但我无法让它工作。 Any tips? 有小费吗? I have read all the tutorials, I enabled the /Za option, and named my file as .c (not .cpp). 我已经阅读了所有教程,我启用了/ Za选项,并将我的文件命名为.c(而不是.cpp)。 However, the following program still builds successfully: 但是,以下程序仍然成功构建:

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

But it shouldn't. 但它不应该。 It would have to be like this to respect the ANSI C standard: 它必须像这样尊重ANSI C标准:

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

I would like the equivalent of the GCC options " -ansi " and " -Wpedantic ". 我想要相当于GCC选项“ -ansi ”和“ -Wpedantic ”。 Is this even possible in VS? 这在VS中甚至可能吗?

From this page , MSVC 2015 seems to only support C99: 这个页面来看,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). C99一致性 Visual Studio 2015完全实现了C99标准库,但依赖于Visual C ++编译器尚不支持的编译器功能的任何库功能除外(例如,<tgmath.h>未实现)。

There is no mention of C89 compatibility anywhere on that page. 在该页面的任何地方都没有提到C89兼容性。

The /Za switch only disables Microsoft specific extensions: /Za开关仅禁用Microsoft特定扩展:

The Visual C++ compiler offers a number of features beyond those specified in either the ANSI C89, ISO C99, or ISO C++ standards. Visual C ++编译器提供了许多超出ANSI C89,ISO C99或ISO C ++标准中指定的功能。 These features are known collectively as Microsoft extensions to C and C++. 这些功能统称为C和C ++的Microsoft扩展。 These extensions are available by default, and not available when the /Za option is specified. 这些扩展在默认情况下可用,并且在指定/ Za选项时不可用。 For more information about specific extensions, see Microsoft Extensions to C and C++. 有关特定扩展的详细信息,请参阅Microsoft Extensions to C和C ++。

It will not disable non-Microsoft specific extensions if they are part of an official C standard that it supports (like C99). 如果它们是它支持的官方C标准(如C99)的一部分,它将不会禁用非Microsoft特定扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM