Click here to Skip to main content
15,886,734 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

Is there any C-code editor (not VS) that support syntax highlighting depending on (common) preprocessor directives, e.g. if I have a #ifdef bla foo #endif, and bla is not #defined in the file, and not #defined in any of the files that is included in the file, then the code is for instance greyed out ?
Posted
Comments
Philippe Mori 8-Oct-15 12:35pm    
Why not VS?
Rage 8-Oct-15 19:11pm    
Because I basically only need a code "viewer" - I do not code myself - and VS is far too expensive for that.
I think I will install the compiler and have a run with the option that only stripes out non-compiled code. I did not want to have to rerun the compiler each time I change the #defines, but I guess this is still something that is not possible easily in 2015...
Philippe Mori 9-Oct-15 12:13pm    
See my solution. Microsoft offer at least 3 free products that allows you to view and edit code and as far as I know two of them can be used by anyone in any organisation...
Rage 9-Oct-15 12:15pm    
Ok, but the preprocessor part is important. Does Code handle it ?
Philippe Mori 9-Oct-15 12:55pm    
I have not tried it so my guess would be that it would handle it as VS... Try it yourself.

The problem with #define symbols is that there are so many places to define them: in #include files that are located in some project-specific path, in the project setting itself, in environment variables (indirectly), or on the command line. That makes it very hard for any editor short of full IDE-capabilities to correctly interpret them! More importantly, project settings are often stored in an IDE-specific file/format, so whether a specific code editor is suitable to view your code depends on its ability to interpret the project settings file that you have!

Note that VisualStudio 2015 Community edition is free (requires registration though) and its download can be configured to only install (and download) the relevant C/C++ parts, skipping the expansive .NET library entirely! Previous releases also provided free versions, but they're typically several GB to download and install. We're talking of a factor of about 5-10 in both size and time required!

Of course, if the files you're looking at are not from Visual Studio to start with, then it may indeed be easier and better to just use one of the editors suggested above.
 
Share this answer
 
I would recommand Notepad++ which supports a lot of languages, is high customizable and has a lot of useful plugins.

If you fizzle around you can develop own highlighting rules.
 
Share this answer
 
About any editor for programmer is doing syntax highlighting.

But there, you want it to evaluate #defines, I have never needed such a thing because I know What I am doing and why I have some #ifdef in my code. And I have a common usage that is to build for different targets and the #define are given to compiler directly on command line. I guess that it defeat this feature :)

And I prefer to know that only real comments are highlighted as comments and nothing else.

To be really efficient, your editor almost need to embed a compiler to evaluate the preprocessor directives.

Personally, I use UltraEdit, which fit my needs.
 
Share this answer
 
Comments
Philippe Mori 12-Oct-15 9:16am    
In my opinion, best syntax highlight for #ifdef that are not defined, is dimmed colors as Visual Studio does for C++ code. Thus you clearly see what is not included as the color are lighter (assuming blue/light theme ; probably darker with dark theme).

I would like if Visual Studio would do that for C# too. It would be even better if the editor would have some functionality available like Find references, IntelliSense and more that could work even in those block that are not included.
You can take a look at that : Visual Studio Code[^]

Otherwise Express and Community edition of Visual Studio are free. But it is a large installation if you seldom read code...
 
Share this answer
 
Comments
Stefan_Lang 12-Oct-15 4:23am    
VS 2015 CE is in fact quite slim and quick to install if you don't explicitely select the .NET library for installation. But for previous releases I absolutely agree: I rarely bothered installing new versions mostly because I felt the time and space requirements weren't worth it!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900