IBM Z and LinuxONE - Languages

Languages

Languages

Broad range of supported development languages and tools allows to transform software delivery practices.

 View Only

C++11: C99 long long

By FANG LU posted Tue March 24, 2020 07:40 PM

  

Compared with C++98, C++11 supports two integer types long long and unsigned long long, which were introduced in the C99 standard before. The C++11 standard supports these two integer types to be compatible with the C99 standard.


The long long and unsigned long long types can have different lengths on difference platforms, but the C++11 standard requires that their length should be at least 64 bits. When we define an integer literal, we can use suffix LL (ll) to indicate the type of the literal is long long, and use suffix ULL (ull, Ull, uLL) to indicate the type of the literal is unsigned long long. In the following example, variable x is of type long long and its value is -9500000000000000000. Variable y is of type unsigned long long and its value is 9500000000000000000.


  long long int x = -9500000000000000000LL;

  unsigned long long y = 9500000000000000000ULL;


We call this feature as the C99 long long feature. The following example shows the different behaviors when the C99 long long feature is enabled and disabled:


  #include <stdio.h>

  int main(){

    if(0>3999999999-4000000000){

      printf("C99 long long is enabled");

    }

    else{

      printf("C99 long long is disabled");

    }

  }


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 the C99 long long feature is enabled, the two values have the long long int type, so the difference of 3999999999 and 4000000000 is negative. Otherwise, if the C99 long long feature is disabled, the two values have the unsigned long type, so the difference is positive.


To strictly conform to the C++11 standard, the z/OS XL C/C++ compiler introduces the extended integer safe behavior to ensure that a signed value never becomes an unsigned value after a promotion. After this behavior is enabled, if a decimal integer literal that does not have a suffix containing u or U cannot be represented by the long long int type, the compiler issues an error message to indicate that the value of the literal is out of range. 

0 comments
0 views

Permalink