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;
}
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++)
{
}
}
I would like the equivalent of the GCC options "-ansi" and "-Wpedantic". Is this even possible in VS?
From this page, MSVC 2015 seems to only support 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).
There is no mention of C89 compatibility anywhere on that page.
The /Za
switch only disables Microsoft specific extensions:
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++.
It will not disable non-Microsoft specific extensions if they are part of an official C standard that it supports (like C99).