Mail Archives: djgpp/1998/03/01/17:30:20
Noam Rotem wrote in message ...
>Maybe it's trivial, but why is there a data type which its size
>can be different in different compilers? I refer to 'int'. Why
>can it be 2 or 4 bytes, depending on the implementation? What's
>the logic?
I may be wrong, but I believe the ANSI standard imposes these rules:
char 1 byte
short <= sizeof(int)
int <= sizeof(long)
unsigned == sizeof(int)
float <= sizeof(double)
So you can see that there is a fair degree of latitude in how the size of
the variable types are set. The sizes are probably based on the size that
the CPU natively handles the fastest, i.e. 32-bit code would have a 4-byte
int.
Matt.
- Raw text -