C provides four modifiers that can be applied to basic data types:
signed: Allows the variable to hold both positive and negative values (this is the default for int and char).
unsigned: Forces the variable to hold only positive values (and zero). This effectively doubles the maximum positive range.
short: Reduces the storage space of a variable (usually to 2 bytes for an integer), which is useful for saving memory in embedded systems.
long: Increases the storage space of a variable (usually to 8 bytes for long long), allowing it to store much larger numbers.
The size of these types can vary depending on the compiler, but here are the typical values for a 32-bit/64-bit system:
| Type Combination | Size (Bytes) | Range |
| short int | 2 | $-32,768$ to $32,767$ |
| unsigned short int | 2 | $0$ to $65,535$ |
| unsigned int | 4 | $0$ to $4,294,967,295$ |
| long long int | 8 | Very large (19+ digits) |
| unsigned char | 1 | $0$ to $255$ |
As you progress toward STM32 development, you will find that modifiers are critical for two reasons:
Memory Optimization: On microcontrollers with limited RAM, using short instead of int when a value will never exceed 30,000 can save significant space.
Hardware Interaction: When reading sensor data that only yields positive values (like a pulse rate or distance), using unsigned ensures your logic doesn't accidentally treat a large positive value as a negative one.
Copyright ©2025. All Rights Reserved Emblab THE RAVE INNOVATION