[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
enums and unsigned ints in g++ 3.4.0 (x86_64)
From: |
sridhar |
Subject: |
enums and unsigned ints in g++ 3.4.0 (x86_64) |
Date: |
7 Sep 2004 08:35:24 -0700 |
The following code gives unexpected results on an AMD64 machine
g++ 3.4.0
enum Type {
TypeA = 0x01,
TypeB = 0x29
};
static const unsigned int TypeC = 0x20;
int main(void)
{
Type T = TypeB;
if(T & TypeC)
printf("matches\n");
}
The assembly code produced is
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 83 ec 10 sub $0x10,%rsp
8: c7 45 fc 20 00 00 00 movl $0x20,0xfffffffffffffffc(%rbp)
f: 83 7d fc 00 cmpl $0x0,0xfffffffffffffffc(%rbp)
// isn;t that strange,comparing with 0
'
13: 79 0f jns 24 <main+0x24>
15: bf 00 00 00 00 mov $0x0,%edi
1a: b8 00 00 00 00 mov $0x0,%eax
1f: e8 00 00 00 00 callq 24 <main+0x24>
24: b8 00 00 00 00 mov $0x0,%eax
29: c9 leaveq
2a: c3 retq
On an x86 machine this works fine and prints 'matches' as expected.
I guess the enums in the above code would be signed ints.
If I change the condition to
if(T & (int)TypeC)
it works. So what exactly is happening here?
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- enums and unsigned ints in g++ 3.4.0 (x86_64),
sridhar <=