Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 159
Here is an example of code that may fail because the default type assigned to a con-
stant is not appropriate:
unsigned long int result;
unsigned char shifter;
void main(void)
{
shifter = 20;
result = 1 << shifter;
// code that uses result
}
The constant 1 (one) will be assigned an int type, hence the result of the shift opera-
tion will be an int. Even though this result is assigned to the long variable, result, 
it can never become larger than the size of an int, regardless of how much the con-
stant is shifted. In this case, the value 1 shifted left 20 bits will yield the result 0, not 
0x100000.
The following uses a suffix to change the type of the constant, hence ensure the shift 
result has an unsigned long type.
result = 1UL << shifter;
5.4.6.2
FLOATING-POINT CONSTANT
Floating-point constants have double type unless suffixed by f or F, in which case it 
is a float constant. The suffixes l or L specify a long double type which is consid-
ered an identical type to double by MPLAB XC8.