This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Problem with sizeof (mingw32 and cygwin32)


| I obtain as exit (mingw32):  
|   
| int 4 bytes  
| long int 4 bytes  
| long long int 8 bytes  
| float 4 bytes  
| double 8 bytes    
| long double 12 bytes      
|   
| Would not the correct be (in the order) 4, 8, 16, 4, 8, 12 bytes?  

Nope, this is correct.  There are lots of architectures that
use the same size for int and long.

[ I think that the historical reason is that in the past the
data-bus of a cpu was 8 bits (called a byte for that reason)
and an integer was just that: an integer, 2 bytes wide.
Later when the databus became 16 bits, nothing changed and we
had char = 1 byte, int = 2 bytes and long = 4 bytes.  Now the
databus has become 32 bits, an 'int' became 4 bytes too:
because keeping it 2 bytes would only make the programs slower.
The size of a long wasn't changed, and a long long has been
added.  There are already cpu's that have a databus of 64 bits,
and those have int = 4 bytes, long = 8 bytes.  You might have
expected 'int = 8 bytes, long = 8 bytes ...' but a tradeof between
speed and memory usage had to be made;  lots of programs use
arrays of ints.
If you insist on having *exactly* 32 bits, then you can't rely
on using 'int' or 'long' and you should use int32_t instead. ]

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]