Microchip Technology SW006021-1N ユーザーズマニュアル
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 158
2012 Microchip Technology Inc.
5.4.6
Constant Types and Formats
A constant is used to represent an immediate value in the source code, as opposed to
a variable that could hold the same value. For example 123 is a constant.
a variable that could hold the same value. For example 123 is a constant.
Like any value, a constant must have a C type. In addition to a constant’s type, the
actual value can be specified in one of several formats.
actual value can be specified in one of several formats.
5.4.6.1
INTEGRAL CONSTANTS
The format of integral constants specifies their radix. MPLAB XC8 supports the ANSI
standard radix specifiers, as well as ones which enables binary constants to be
specified in C code.
standard radix specifiers, as well as ones which enables binary constants to be
specified in C code.
The formats used to specify the radices are given in Table 5-7. The letters used to spec-
ify binary or hexadecimal radices are case insensitive, as are the letters used to specify
the hexadecimal digits.
ify binary or hexadecimal radices are case insensitive, as are the letters used to specify
the hexadecimal digits.
Any integral constant will have a type of int, long int or long long int, so that
the type can hold the value without overflow. Constants specified in octal or hexadeci-
mal may also be assigned a type of unsigned int, unsigned long int or
unsigned long long int
the type can hold the value without overflow. Constants specified in octal or hexadeci-
mal may also be assigned a type of unsigned int, unsigned long int or
unsigned long long int
if the signed counterparts are too small to hold the value.
The default types of constants may be changed by the addition of a suffix after the dig-
its; e.g., 23U, where U is the suffix. Table 5-8 shows the possible combination of suf-
fixes and the types that are considered when assigning a type. So, for example, if the
suffix l is specified and the value is a decimal constant, the compiler will assign the
type long int, if that type will hold the constant; otherwise, it will assigned
long long int
its; e.g., 23U, where U is the suffix. Table 5-8 shows the possible combination of suf-
fixes and the types that are considered when assigning a type. So, for example, if the
suffix l is specified and the value is a decimal constant, the compiler will assign the
type long int, if that type will hold the constant; otherwise, it will assigned
long long int
. If the constant was specified as an octal or hexadecimal constant,
then unsigned types are also considered.
TABLE 5-7:
RADIX FORMATS
Radix
Format
Example
binary
0b number or 0B number
0b10011010
octal
0 number
0763
decimal
number
129
hexadecimal
0x number or 0X number
0x2F
TABLE 5-8:
SUFFIXES AND ASSIGNED TYPES
Suffix
Decimal
Octal or Hexadecimal
u
or U
unsigned int
unsigned long int
unsigned long long int
unsigned int
unsigned long int
unsigned long long int
l
or L
long int
long long int
long int
unsigned long int
long long int
unsigned long long int
u
or U, and l or L
unsigned long int
unsigned long long int
unsigned long int
unsigned long long int
ll
or LL
long long int
long long int
unsigned long long int
u
or U, and ll or LL
unsigned long long int
unsigned long long int