?
Solved

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

Posted on 2003-11-30
2
Medium Priority
?
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 19

Accepted Solution

by:
Dexstar earned 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.
Suggested Courses

771 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