I'm using gcc, which implements enums as 32 bit integers on the architecture I have (don't know in general). If I try to assign an enum value too large, I get
warning: integer over开发者_如何学编程flow in expression
Is there a way to make gcc use 64 bit integers as the underlying integer type? A gcc specific way is fine, although if there's a portable way, that's even better.
** Edit ** This is a related post: 64 bit enum in C++?
Unlike that question, I'm also interested in gnu extensions.
The following works for me with -std=c++0x
, but not with -std=c++98
though
enum EnumFoo {
FooSomething = 0x123456789ULL
};
I tested this with
$ g++ --version
g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
one option: create a template class with a static const
member of a specific type.
for example std::tr1::integral_constant
, declared in c++/tr1/type_traits in the GNU distribution (at least, the one i'm using).
for an enum value: your declaration could matter (e.g., use U
, L
as appropriate)
精彩评论