Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I was doing some small exercises in C with a friend, and I kept using keywords from newer languages (e.g. bool, new) out of habit. It took me a while to realize that was the issue because VS kept highlighting them as keywords, even though they aren't in C.

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

Using VS2010 if it matters.

like image 236
Jimmy Avatar asked Apr 13 '11 07:04

Jimmy


1 Answers

You cannot. This is a known bug in Visual Studio. The "Intellisense" mechanism which is used for syntax coloring in Visual Studio is based on the EDG C++ compiler which Microsoft bought, since their Visual C/C++ compiler is poorly suited for the incremental parsing required to handle on-the-fly analysis of incomplete code. And the EDG compiler is C++ only.

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

 #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 inactive, and only the C++ side will be colored! That's because the Intellisense syntax colorer, based on the EDG C++ compiler, believes that everything is C++.

like image 75
librik Avatar answered Sep 29 '22 01:09

librik