How to get C syntax highlighting (not C ++) in Visual Studio (2010)?

I did some small exercises in C with a friend, and I still used keywords from newer languages ​​(e.g. bool, new). It took me a while to figure out that this is a problem because VS kept highlighting them as keywords, even if they are not in C.

I made sure all my files were * .c, and I set the project properties to compile as C. However, the editor always added highlightint syntax for C ++ keywords in addition to C. keywords. Is there any way to tell Visual Studio that I just want simple c?

Use VS2010 if that matters.

+7
c visual-studio visual-studio-2010
source share
2 answers

You can not. This is a known bug in Visual Studio. The Intellisense mechanism used to color syntax in Visual Studio is based on the EDG C ++ compiler, which Microsoft bought because its Visual C / C ++ compiler is poorly suited for the incremental parsing necessary to process the "incomplete" code of the incomplete code. And the EDG compiler is only C ++.

You can see an example of this by creating the file foo.c, which compiles as C. Then add the following lines to the file:

#ifdef __cplusplus #error C++ is what I am #else #error A bunch of C code! #endif 

When you compile your program, you will see the error message "A bunch of C! Code." But when you look at the Visual Studio editor window, the C side will be grayed out and marked as inactive, and only the C ++ side will be displayed! This is because Intellisense syntax coloring, based on the C ++ EDG compiler, considers all of this to be C ++.

+6
source share

Note that some C ++ functions were adopted by C (C99 std), such as C ++ (//) style comments or the boolean (bool) data type.

0
source share

All Articles