Microsoft C / C ++ Compiler Switch, Needed to Locate Local Variables

I am compiling some C files using Microsoft C / C ++ and complain about declaring local variables inside the block. To state them at the beginning of the block is, of course, good. Which compiler can I use to suppress the errors I get?

Very important,

Kris

+4
source share
4 answers

In C89 and earlier, all block region variable declarations must appear before any statements. C99 changed this rule so that declarations and statements can be mixed up, as in C ++.

Unfortunately, Microsoft decided not to support C99 in Visual Studio and does not plan AFAIK.

+5
source

In the C standard, you cannot declare variables anywhere except at the beginning. This is different from C ++, where variables can be declared anywhere.

So, you should compile the files as if they were C ++ through /TP .

See this article for more details.

+2
source
 CL.exe /Tpfilename 

This means "compile as C ++ regardless of extension."

Or, in other words, what you do is illegal in C, so of course he complains. Either change it to C ++, or make it read like C ++.

0
source

You can use / TP to force the compiler to compile them as C ++ files. However, I'm not sure if this is what you want.

0
source

Source: https://habr.com/ru/post/1334707/


All Articles