C2143 in cstdio

C2143 in cstdio

It is rather interesting when the standard library returns compile errors:

> c:\program files (x86)\microsoft visual studio 9.0\vc\include\cstdio(39) : error C2143: syntax error : missing '{' before ':'
> c:\program files (x86)\microsoft visual studio 9.0\vc\include\cstdio(39) : error C2059: syntax error : ':'

This C2143 error is caused by the inclusion of C++ code within a .c file. Renaming the file from *.c to *.cpp will solve the compile error. However, in some circumstances it is not ideal to rename the file. Then the error can be solved by instructing Visual Studio to compile the project as C++ with the /TP option.

When we look at the project’s properties, we can see the project is already set to compile as C++:

The occurrence of the compile error while the flag is set is due to the default arguments not triggering the same behaviour as when the same argument value is manually specified. Selecting another option and then manually setting the same /TP compile flag solves the compile error:

Leave a Reply

Your email address will not be published. Required fields are marked *