twitter
    Find out what I'm doing, Follow Me :)

Characteristics of Variable Types

One unfortunate problem with C (and some other languages) is that the actual size of variables is somewhat dependant upon the machine (and compiler) being used. Difficulties are sometimes experienced when moving code from one machine to another due to this. A general rule of thumb for modern compilers is that char is at least 8 bits, short is at least 16 bits, long is at least 32 bits, int is the same as either short or long (which causes lots of code conversions come unstuck), float is at least 32 bits, and double is at least as wide as float. As a consequence, you should use either short or long in preference to int (despite its heavy use in this tutorial), and should avoid double where possible. Note that using short instead of int may save an extra memory access, and help speed up code, especially in large loops.

integer 32 bit (assembles as .l, or ±2147483648)
character 8 bit (0 to 255)
float 32 bit (about 1038)
double 64 bit (10308 maximum)
short 16 bit (assembles as .w, or ±32767)
long 32 bit (assembles as .l, or ±2147483648)


Byte ordering is another problem encountered when converting programs from one machine to another. In the 68000, the low byte of a 16 bit word is the second, odd numbered, byte. The bytes in a 32 bit long are laid out most significant byte at the address, with the least significant byte below it. Intel chips use the opposite order. This byte sex problem leads to arguments akin to those in religion and politics, and just as likely to lead to real solutions.