C Programming Data Type Qualifiers

Last modified by Microchip on 2023/11/09 09:07

The fundamental data types may be modified by the prefixes signed, unsigned, short, and long. These modifications change the range of values that can be represented by the fundamental data type.

Modified Integer Types

Qualified TypeMinMaxSize (Bits)
unsigned char02558
char, signed char-1281278
unsigned short int06553516
short int, signed short int-327683276716
unsigned int06553516
int, signed int-327683276716
unsigned long int0232-132
long int, signed long int-231231-132
unsigned long long int0264-164
long long int, signed long long int-263263-164

The keyword int is optional when it is modified (shown in italics in the table above). For example, an unsigned int could be specified more simply as unsigned. The only time int must appear is when used by itself.

Also, note that the fundamental data types are all signed by default. So, int and signed int mean exactly the same thing. signed is not required but is often used when one wants to make their code explicitly clear.

Some compilers, such as the legacy MPLAB® C18 compiler, support the apparently contradictory short long, which is typically defined to be 24 bits. This data type is usually found on compilers that support digital signal processors where 24-bit data is used in high-end audio applications.

As with the fundamental data types, the sizes shown in the table above may vary from one compiler to the next. For example, the short modifier has no effect on int with the MPLAB XC16 compiler, while the MPLAB XC32 compiler defines a short as 16-bits versus the full int as 32 bits.

Modified Floating Point Types

On the floating point side of data types, the only valid qualifier is long and it is typically used only with double.

Qualified TypeAbsolute MinAbsolute MaxSize (Bits)
long double±~10-323.3±~10308.364

Most compilers define float and double as shown in the table above while some allow long to be applied to float and double. The data above is representative of the MPLAB XC16 compiler but should be similar for all IEEE-754 format floating point implementations.

Some compilers provide a setting or command line switch that will force the double to behave as a long double in the table.