Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting to C# also VS2015 5 117
thread-safe code in c++ 2 84
Dynamically allocate memory 9 56
c++, dynamic object by json 1 24
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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

920 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

17 Experts available now in Live!

Get 1:1 Help Now