Hello..
What is the best way to store enum? I usually use unsigned short..
What about you guys?
Hello..
What is the best way to store enum? I usually use unsigned short..
What about you guys?
What is wrong with enums themselves?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Do you mean:
Code:enum e_num { SOME_ENUM, ENUM_2 }; e_num test = ENUM_2;
I think we really can call this thing enum
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
If you need to store an enum value as a regular type, use int (or unsigned int). The only reason to use short would be if you were storing a huge number of them and needed to save the space.Code:typedef enum { RED, GREEN, BLUE } RGBColor; RGBColor myRGBColor = BLUE;
If you mean as just a variable in your code, use the type of the enum (e.g. e_num as above). If you mean for transmission across the wire, use whatever is big enough.Originally Posted by l2u
Otherwise you'll have to clarify what you mean by "store".
works as well.Code:enum RGBColor { RED, GREEN, BLUE }; RGBColor myRGBColor = BLUE;
"If you tell the truth, you don't have to remember anything"
-Mark Twain
In C++; not in C. In C you must specify enum before the tag name, or use a typedef.
Of course, this is the C++ forum, but it's still good to know.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.