Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

733 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