Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of integer in C [duplicate]

Tags:

c

int

gcc

Possible Duplicate:
Does the size of an int depend on the compiler and/or processor?

Does the size of Integer depend on Compiler or on OS or on Processor? What if I use gcc on both 32 bit OS or 64bit OS running either on 32 bit machine or 64 bit machine(only 64 bit OS in this case).

like image 336
0x07FC Avatar asked Dec 13 '22 10:12

0x07FC


1 Answers

It depends on the combination of compiler, processor and OS.

For instance, on a 64 bit Intel CPU, in 64 bit mode, the size of a long int in Windows is 4 byte while in Linux and on the Mac it is 8 byte. int is 4 bytes in all three OSes on Intel.

The compiler implementer also has a choice, but usually uses what the OS uses. But it could well be that a compiler vendor that has C compilers for all three platforms decides to use the same sizes in all three.

Of course, it doesn't make sense to make int 4 bytes (although it would be possible) on a 16 bit CPU.

So it depends on all three things you mention.

like image 186
Rudy Velthuis Avatar answered Dec 14 '22 23:12

Rudy Velthuis