user11114632
user11114632

Reputation:

How do I use Visual Studio 2017 to only compile C code and not take into account c++?

In the C language, you are not allowed to make declarations after the first functional statement, however, when I compile my program with this error, it still works and c++ takes over. How do I stop this from happening?

Upvotes: 1

Views: 162

Answers (1)

Jabberwocky
Jabberwocky

Reputation: 50831

The C compiler used by Visual Studio 2017 is more or less C99 compliant.

In C99 variables can be declared elsewhere that at the beginning of a scope, just like in C++.

So this code snippet is a valid C99, but it's not valid C89:

int foo(void)
{
  printf("Hello. ");
  int bar = 2;
  printf("Bar = %d\n", bar);
}

This is valid C89:

int foo(void)
{
  int bar = 2;
  printf("Hello. ");
  printf("Bar = %d\n", bar);
}

More information here: https://en.wikipedia.org/wiki/ANSI_C#C89

Upvotes: 2

Related Questions