1

I have a C project which i open in VisualStudio 2019 with the "Open folder" option. I added a CppProperties.json to get Intellisense running, but now it throws errors if i try to declare a variable in a for loop like this:

for (int i = 0; i < 10; i++)
{
}

error: E0029 expected an expression
error: E0020 identifier "i" is undefined

I searched StackOverflow already and found this thread where someone mentions that the declaration of variables in for loops was added in the C99 standard.

In the VisualStudio documentation it says you should add "-std=C99" to your project settings, but i have no project file (because I opened it with the "Open Folder" option) and therefore no project settings.

Is there a way to tell Intellisense what C standard to use anyways ?

Thanks in advance.

Michael
  • 147
  • 7
  • 1
    Visual Studio and the Microsoft Visual C++ compiler is, first and foremost, a C++ compiler and environment. C has been a third-class citizen in the Visual Studio system for a long time, and not until very recently the compiler itself started to support C99. – Some programmer dude Oct 15 '20 at 07:51
  • 2
    Using MSVC as a C compiler is a bit like using your washing machine to wash your dishes. – Bathsheba Oct 15 '20 at 07:52

1 Answers1

2

Found it: Just add

"compilerSwitches": "-std=c99",

to your CppProperties.json.

Michael
  • 147
  • 7