Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

enum's... convinient, but used too often?

Status
Not open for further replies.

zanza

Programmer
Feb 18, 2002
89
US
enum's are very nice, they make organizing and indexing into complicated arrays painless, and they make the code a little more logical for other readers.

but what im curious about is: what would any of you say would be considered using too many enumerators?

žÅNžÅ
 
Normally it is the case of not enough enums and too many #defines. I've actually run out of space for #defines on two projects: one on RMX and one on Windows but I've never run out of space on enums yet. Mind you - they were fairly big projects in the late-80s early-90s when 4Mb was a lot of memory.
 
:) well thats good to hear.

ive started a project in which i already have three enums that average 12 symbols. its so much easier with them, but you know what they say about too much of a good thing.

*shrug*

thanks for your reply.

žÅNžÅ
 
What you really need is a naming convention of some sort so that you know it is an enum and from which set. It is more convenient to have
Code:
enum dirn { north, south, east, west };
enum posn ( top, bottom, left, right };
than
Code:
enum Dirn { DirnNorth, DirnSouth, DirnEast, DirnWest, DirnMax };
enum Posn { PosnTop, PosnBottom, PosnLeft, PosnRight, PosnMax };
but the latter has benefits - you know it is Dirn or Posn. I always have a Max so I can use it in loops and arrays. I always find enums better than #defines because I can see what they are in the debugger. Problem is getting too comfortable with enums and then having to go to a language like Java which doesn't have them (doesn't have #defines either). You have to think really hard about how to code something.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top