On Sun, 9 Oct 2005 15:18:45 +0100, "Fraser Ross" <f@ross.co.uk> wrote:
void f(unsigned int const x) {
};
int main(int argc, char* argv[]){
//unsigned short a=0xFFFF;
enum { a=0xFFFF };
f(a*0x10000+0xFFFF);
return 0;
}
I get an arithmetic overflow when using a as an enum. I prefer
constants to be enum values so I have a problem with this.
Fraser.
Well, it overflows ... what else did you expect? You need to cast
either a or 0x10000 to a larger type than int to avoid the overflow.
Default integer promotion uses int instead, which is too small to
accommodate the resulting value.
Try this instead (if your platform supports UINT64 natively, you can
comment out the typedef or change it to "unsigned long long" instead
of __int64):
// test_enum.cpp
typedef unsigned __int64 UINT64;
void f(UINT64 const x) {
};
int main(int argc, char* argv[]){
//unsigned short a=0xFFFF;
enum { a=0xFFFF };
f(a*((UINT64)0x10000)+0xFFFF);
return 0;
}
--
Bob Hairgrove
No**********@Home.com