Solved

Visual Studio.NET 'C/C++' Gives Active Text the Inactive Text Color Between Preprocessor Directives

Posted on 2008-06-18
2
1,319 Views
Last Modified: 2010-08-05
I am still having the same problem in VS 2008 that I had in VS 2005.  It was somewhat intermittent in VS 2005, but seems to be a constant problem in VS 2008.

Let's say that "_RDEF3" is a preprocessor directive.  [I assigned "_RDEF3" in the Configuration Properties->C/C++->Preprocess Definitions section of the project properties]

I have code that states:

#ifdef _RDEF3
      blah
      blah
      blah
#else
      blah2
      blah2
      blah2
#endif

When Visual Studio detects code between #ifdef's that is inactive, it displays it in gray.  This is a really nice feature -- when it works.

The problem is that the "blah" text above, between the "#ifdef _RDEF3" and "#else" is grayed out and the "blah2" text is not.  However, when I debug the code, the "blah" text gets executed because "_RDEF#" is, in fact, a preprocessor directive.

Very strange.  On the one hand, VS thinks the text is inactive when in the text editor, on the other, it executes it because it thinks it IS active.

If I remove the "_" in "_RDEF3" then put it back, the "blah" text *DOES* become active.  But not for long.  If I press F5 to start executing the Debug version of the code, it immediately goes back to gray.


I thought VS 2008 would have fixed this by now.

0
Comment
Question by:richelieu7777
2 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 21817584
One workaround for this - not nice, I know - is to use #define directives instead of the project settings. This also exposes the same glitch sometimes, but *most* of the time it's consistent.
0
 

Accepted Solution

by:
richelieu7777 earned 0 total points
ID: 21821993
Thanks,  but I think I found the fix.  "Selecting "Clean Solution" then "Rebuild Solution" doesn't help at all.  However, when I use a program I wrote a while back to remove all project binary files, it fixed the problem.

I wrote this program when developing under Visual C 6.0 to #1)  reduce folder sizes of project copies I want to keep, #2)  prevent conflicts when debugging a previous project.  Therefore, it would force the compiler to re-create all binary files from scratch rather than relying on any previously existing files.

I didn't realize, however, that a 3rd benefit to this program is that it also fixes this issue in Visual Studio.NET.  I ran it just now and it fixed the problem.

The program deletes all the following files from the project folder:

     obj
     sbr
     idb
     bsc
     ilk
     pdb
     plg
     pch    
     ncb


I'm going to keep this question open just a little bit longer to see if anybody has found a better solution; for example, turning on "such & such" compiler option, or a patch from Microsoft or something.


0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now