Solved

Problem with enum delcaration moving from VC++6.0 -> VC++. .Net

Posted on 2003-11-30
2
186 Views
Last Modified: 2010-04-01
I have to move an old C++ project up to VS.net from 6.0.

i have a declration:

typedef enum
{
     DEBUG =0,
     BLAH,
     BLAH
} MyEnum;

which under .Net gives me
     " syntax error : missing '}' before '='"    
on the DEBUG line

Now i assume that since "DEBUG" is not in its own namespace and im doing a debug build that there are issues with DEBUG already defined. (and the problem goes away under a release build).
My question then is how is it that this simple problem doesnt occur when using 6.0 and then how can i get it to compile under .net?


Thanks.



0
Comment
Question by:tamarind
  • 2
2 Comments
 
LVL 19

Accepted Solution

by:
Dexstar earned 125 total points
ID: 9847553
@tamarind:

> Now i assume that since "DEBUG" is not in its own namespace and im doing a
> debug build that there are issues with DEBUG already defined. (and the problem
> goes away under a release build). My question then is how is it that this
> simple problem doesnt occur when using 6.0 and then how can i get it to compile
> under .net?

The issue is that "DEBUG" has been #defined to something.  It seems it is defined differently under the two compilers, which is why it breaks on you.  I think that under .NET, DEBUG is not defined as particular value, so all the references get removed, so your line becomes:
     =0,

Which is what the compiler was complaining about.  Under VC6, it might have been defined as some other value, that would make it work, for whatever reason.  It might not have been defined at all (sometimes _DEBUG is used).

Using keywords as your own value names is not a good idea.  DEBUG is not a true keyword, but it does have special meaning under at least some compilers.  My suggestion is that you change DEBUG in your source to some other name (Visual Studio has a nice search/replace that will span multiple files), and try pick names that don't overlap.

Hope That Helps,
Dex*
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9847584
@tamarind:

> i have a declration:

Sometimes in my enumerated types, I will use the name of the type as a prefix to the individual values.  That way, I can tell at a glance that the value is part of that enum type.  It also helps to eliminate name collisions (Both of which are nice when you have projects with many enum types).

Applying this system to your type, it would look like this:
     typedef enum
     {
          MyEnum_DEBUG = 0,
          MyEnum_BLAH,
          // Other values go here
     } MyEnum;

Dex*
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.

758 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

22 Experts available now in Live!

Get 1:1 Help Now