Strange enum type conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi experts,

I'm not sure whether it is a gcc bug or a feature. In the following
enum's (see code below) the en1 and en2 are converted to a 64 bit type
("long long int" in i686 GNU/Linux or "long int" in x86_64 GNU/Linux).
However, if printing it directly via the first printf command, the
numbers are interpreted as a 32 bit type.

As a result I get the following output:
1 << 31: 80000000, 0xffffffff: ffffffff 
Enums: ffffffff80000000, ffffffff 


Code enums.cpp (32 bit version):

-------------------------------

#include <stdio.h>

enum 
{
  en1  = 1 << 31 /*0x80000000*/
 ,en2 =  0xffffffff

};

int main ()
{
  printf("1 << 31: %x, 0xffffffff: %x \n", 1 << 31, 0xffffffff);
  printf("Enums: %llx, %llx \n", en1, en2);
}

------------------------------

For 64 bit the second printf should be replaced by:
  printf("Enums: %lx, %lx, \n", en1, en2);

I compiled it with:
g++ -g -o enums.cpp enums.cpp

Has anybody an idea, why the enum types are converted to 64 bit?

Thanks a lot,

Hajo



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux