在Visual Studio 2015中强制执行A​​NSI C标准 [英] Enforce ANSI C Standard in Visual Studio 2015

查看:108
本文介绍了在Visual Studio 2015中强制执行A​​NSI C标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. Any tips? I have read all the tutorials, I enabled the /Za option, and named my file as .c (not .cpp). However, the following program still builds successfully:

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

但是不应该.必须遵循ANSI C标准:

But it shouldn't. It would have to be like this to respect the ANSI C standard:

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

我希望使用GCC选项" -ansi "和" -Wpedantic ". 在VS中甚至有可能吗?

I would like the equivalent of the GCC options "-ansi" and "-Wpedantic". Is this even possible in VS?

推荐答案

来自此页面,MSVC 2015似乎仅支持C99:

From this page, MSVC 2015 seems to only support C99:

C99符合性,Visual Studio 2015完全实现了C99标准库,但依赖于Visual C ++编译器尚不支持的编译器功能的任何库功能(例如,< tgmath)除外. h>未实现).

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的兼容性.

There is no mention of C89 compatibility anywhere on that page.

/Za开关仅禁用 Microsoft特定的扩展名:

Visual C ++编译器提供了ANSI C89,ISO C99或ISO C ++标准中指定的功能以外的许多功能.这些功能统称为Microsoft对C和C ++的扩展.这些扩展名默认情况下可用,当指定/Za选项时不可用.有关特定扩展的更多信息,请参见Microsoft对C和C ++的扩展.

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),它将不会禁用.

It will not disable non-Microsoft specific extensions if they are part of an official C standard that it supports (like C99).

这篇关于在Visual Studio 2015中强制执行A​​NSI C标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆