Integer literals

Integer literals are numbers that do not have a decimal point or an exponential part. They can be represented as:
An integer literal might have a prefix that specifies its base, or a suffix that specifies its type.
Read syntax diagramSkip visual syntax diagram
Integer literal syntax

>>-+-decimal_constant-----+--+---------------+-----------------><
   +-octal_constant-------+  +-+-l--+--+---+-+   
   '-hexadecimal_constant-'  | +-L--+  +-u-+ |   
                             | +-ll-+  '-U-' |   
                             | '-LL-'        |   
                             '-+-u-+--+----+-'   
                               '-U-'  +-l--+     
                                      +-L--+     
                                      +-ll-+     
                                      '-LL-'     

The long long features

There are two long long features:
  • the C99 long long feature
  • the non-C99 long long feature
Note: The syntax of integer literals is the same for both of the long long features.

Types of integer literals that are supported in pre-C99 mode

The following table lists the integer literals and shows the possible data types when the C99 long long feature is not enabled.
Table 1. Types of integer literals that are supported in pre-C99 mode1
Representation Suffix Possible data types
    int unsigned int long int unsigned long int
IBM extension
long long int
IBM extension
unsigned long long int
Decimal None +   + +    
Octal, Hex None + + + +    
All u or U   +   +    
Decimal l or L     + +    
Octal, Hex l or L     + +    
All Both u or U and l or L       +    
Decimal ll or LL         + +
Octal, Hex ll or LL         + +
All Both u or U and ll or LL           +
Note:
  1. When none of the long long features are enabled, types of integer literals include all the types in this table except the last two columns.

Types of integer literals that are supported in C99

The following example demonstrates the different behaviors of the compiler when you enable different long long behaviors:
#include <stdio.h>

int main(){
    if(0>3999999999-4000000000){
        printf("C99 long long");
    }
    else{
        printf("non-C99 IBM long long extension");
    }
}
In this example, the values 3999999999 and 4000000000 are too large to fit into the 32-bit long int type, but they can fit into either the unsigned long or the long long int type. If you enable the C99 long long feature, the two values have the long long int type, so the difference of 3999999999 and 4000000000 is negative. Otherwise, if you enable the non-C99 IBM long long extension, the two values have the unsigned long type, so the difference is positive.
When both the C99 and non-C99 long long features are disabled, integer literals that have one of the following suffixes cause a severe compile-time error:
  • ll or LL
  • Both u or U and ll or LL
The following table lists the integer literals and shows the possible data types when the C99 long long feature is enabled.
Table 2. Types of integer literals that are supported in C99
Representation Suffix Possible data types
    int unsigned int long int unsigned long int long long int unsigned long long int
Decimal None +   +   + +
Octal, Hex None + + + + + +
All u or U   +   +   +
Decimal l or L     +   + +
Octal, Hex l or L     + + + +
All Both u or U and l or L       +   +
Decimal ll or LL         + +
Octal, Hex ll or LL         + +
All Both u or U and ll or LL           +

Decimal integer literals

A decimal integer literal contains any of the digits 0 through 9. The first digit cannot be 0. Integer literals beginning with the digit 0 are interpreted as an octal integer literal rather than as a decimal integer literal.

Read syntax diagramSkip visual syntax diagram
Decimal integer literal syntax

                 .--------------.   
                 V              |   
>>-digit_1_to_9----digit_0_to_9-+------------------------------><

See the following examples of decimal literals:

485976
5
A plus (+) or minus (-) symbol can precede a decimal integer literal. The operator is treated as a unary operator rather than as part of the literal. Consider the following example:
-433132211
+20

Hexadecimal integer literals

A hexadecimal integer literal begins with the 0 digit followed by either an x or X, followed by any combination of the digits 0 through 9 and the letters a through f or A through F. The letters A (or a) through F (or f) represent the values 10 through 15, respectively.

Read syntax diagramSkip visual syntax diagram
Hexadecimal integer literal syntax

           .------------------.   
           V                  |   
>>-+-0x-+----+-digit_0_to_f-+-+--------------------------------><
   '-0X-'    '-digit_0_to_F-'     

See the following examples of hexadecimal integer literals:

0x3b24 
0XF96 
0x21 
0x3AA 
0X29b 
0X4bD

Octal integer literals

An octal integer literal begins with the digit 0 and contains any of the digits 0 through 7.

Read syntax diagramSkip visual syntax diagram
Octal integer literal syntax

      .--------------.   
      V              |   
>>-0----digit_0_to_7-+-----------------------------------------><

See the following examples of octal integer literals:

0 
0125 
034673 
03245


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us