The Basic Data Types
|char||The smallest type on an architecture. Usually 8-bits wide. Sign depends on implementation.|
|int||The only type that the modulus operation can be applied on. At least 16-bits in size. Usually 32-bits on 32-bit systems.|
|float||Single precision floating point number. Typically 32-bits wide.|
|double||Double precision floating point number. Typically 64-bits wide, although can be analogous to float (i.e. 32-bits wide) on smaller systems such as 8-bit microcontrollers.|
|long double||Not normally supported on embedded platforms. 128-bits.|
|void||Special case data-type.|
sizeof() can be used to return the number of bytes each type uses.
“There was a young man named Wight,
Who invented the thirteen bit byte.
You’ll get so much more,
from your memory, I’m sure.
But sadly your sizeof ain’t right.”
Fixed-width Integral Types
The problem with using int and all of it’s derivatives ( short int, long int, long long int , e.t.c) is that the width of the integer is platform specific. It is normally the same width as the platforms bus, but at least 16-bits. It is also called the natural width. For example, on an 8-bit system, an int will be 16 bits wide (remember, the C standard specifies it can’t be less than 16 bits). On a 16-bit platform, it will usually be 16 bits, 32 bits for a 32-bit platform, 64 bits for a 64-bit platform, and so on, you get the idea!
To write portable code, it is usually better to use fixed-width integral types.
Fixed-width integral types also need special symbols for printf() statements. These are specified in <cinttypes.h>. They begin with the lettters PRI.
Posted: June 14th, 2013 at 7:25 pm
Last Updated on: August 15th, 2017 at 10:50 am