Hello..
What is the best way to store enum? I usually use unsigned short..
What about you guys?
Printable View
Hello..
What is the best way to store enum? I usually use unsigned short..
What about you guys?
What is wrong with enums themselves?
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
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.Quote:
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;
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.