View the number of bytes occupied by the Keil MDK-ARM for various data types
1. Define several variables to store the number of bytes of each data type.
<Stdio. h>
Unsigned char a, B, c, d, e, f, g;
Main ()
{
A = sizeof (char );
B = sizeof (short INT );
C = sizeof (INT );
D = sizeof (long );
E = sizeof (long INT );
F = sizeof (float );
G = sizeof (double );
While (1 );
}
2. view the storage address of each variable. View --- symbols window.
3. view the stored values of each address. View --- Memory window.
We can see that:
Char occupies 1 byte
Short int occupies 2 bytes
Int occupies 4 bytes
Long occupies 4 bytes
Long int occupies 4 bytes
Float occupies 4 bytes
Double occupies 8 bytes
We can define the macro as follows:
Typedef unsigned char uint8; // unsigned 8-bit integer variable
Typedef signed Char int8; // signed 8-bit integer variable
Typedef unsigned short uint16; // unsigned 16-bit integer variable
Typedef signed short int16; // signed 16-bit integer variable
Typedef unsigned int uint32; // unsigned 32-bit integer variable
Typedef signed int int32; // signed 32-bit integer variable
Typedef float fp32; // Single-precision floating point number (32-bit length)
Typedef double fp64; // double-precision floating point number (64-bit length)