Solved

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

Posted on 2003-11-30
2
198 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

832 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