5.3.2 Integer Data Types
The MPLAB XC8 compiler supports integer data types with 1, 2, 3, 4 and 8 byte widths as well as a single bit type. The table below shows the data types and their corresponding size and arithmetic type. The default type for each type group is bolded.
Type | Size (bits) | Arithmetic Type |
---|---|---|
__bit |
1 | Unsigned integer |
signed char |
8 | Signed integer |
unsigned char |
8 | Unsigned integer |
signed short |
16 | Signed integer |
unsigned short |
16 | Unsigned integer |
signed int |
16 | Signed integer |
unsigned int |
16 | Unsigned integer |
__int24 |
24 | Signed integer |
__uint24 |
24 | Unsigned integer |
signed long |
32 | Signed integer |
unsigned long |
32 | Unsigned integer |
signed long
long |
32/64 | Signed integer |
unsigned long long |
32/64 | Unsigned integer |
The __bit
and __int24
types are
non-standard types available in this implementation. The long long
types
are 64-bit C99 standard types when building for PIC18 or Enhanced Mid-range devices, but
this implementation limits their size to only 32 bits for projects conforming to the C90
Standard or any project targeting any other device.
All integer values are represented in little-endian format with the Least Significant Byte (LSB) at the lower address.
If no signedness is specified in the type, then the type will be
signed
, except for plain char
or
__bit
types, which by default are unsigned
(the
concept of a signed bit is meaningless). The 4.6.3.2 Signed-char Option and 4.6.3.5 Unsigned-char Option control the default type of a plain
char
; however, it is recommended that you always specify the signedness
of all integer types in your source code.
Signed values are stored as a two’s complement integer value.
The range of values capable of being held by these types is summarized in
the declarations for <limits.h>
, contained in the Microchip
Unified Standard Library Reference Guide. The symbols presented there are
preprocessor macros that are available after including <limits.h>
in
your source code. As the size of data types are not fully specified by the C Standard,
these macros allow for more portable code which can check the limits of the range of values
held by the type on this implementation. The macros associated with the
__int24
type are non-standard macros available in this implementation.
The values associated with the long long
macros are dependent on the C
standard being used.
Macros are also available in <stdint.h>
which
define values associated with exact-width types, such as int8_t
,
uint32_t
etc.