HPlogo Communicator 3000 MPE/iX Release 6.5 (Non-Platform Software Release C.65.00) > Chapter 3 Growth Solution

C/iX Supports 64-bit Integers

MPE documents

Complete PDF
Table of Contents
Index

by Walter Murray
Support Technology Lab

In response to a number of customer requests, we have enhanced the C/iX compiler, the C/iX Library, and the MPE/iX Millicode library to provide full support for a 64-bit integer data type. This article provides the information you need in order to declare, operate on, and perform input/output operations on 64-bit integers in C.

All of the changes have been made in such a way as to ensure forward compatibility to MPE/iX 6.5 from pre-6.5 systems. All existing C/iX applications should work the same on 6.5 as they did on earlier systems, whether you recompile and relink on 6.5, or whether you bring your executable programs and libraries forward to 6.5 without recompilation.

However, there are some backward compatibility issues to be aware of if you compile C code on MPE/iX 6.5 and want to move it to a pre-6.5 system. Please see the article "Compatibility Considerations for COBOL and C", elsewhere in this Communicator.

The 64-bit integral type is referred to in C/iX as "long long". The long long data type is an extension to ANSI C. If you compile with the CCXL command and want to use 64-bit integers in ANSI mode, you must enable ANSI extensions by using the compiler option "+e" or "-Ae". If you compile with the c89 command, enable ANSI extensions by specifying "-Wc,+e".

To declare a signed 64-bit integer, use the type specifier "signed long long int", where "signed" and "int" are optional. To declare an unsigned 64-bit integer, use the type specifier "unsigned long long int", where "int" is optional. Note that, for compatibility reasons, the type "long int" remains 32 bits, the same as type "int".

A 64-bit integer is stored in 8 bytes, 8-byte aligned, with higher-order bits stored in lower-addressed bytes. (The high-order 32 bits are stored in the "left" word.)

A signed long long int can represent integers in the range -9223372036854775808 to 9223372036854775807. An unsigned long long int can represent integers in the range 0 to 18446744073709551615.

To write a signed long long integer constant, whether decimal, octal, or hexadecimal, you must use a suffix of "LL". Likewise, an unsigned long long integer constant must be written with a suffix of "ULL". (Suffixes may be written in upper, lower, or mixed case.)

Within your C code you may use variables of type long long the same as you would use variables of any other integral type. For example, a variable of type long long can be used as an operand in an arithmetic or relational expression, as a function argument, parameter, or return, as a subscript, etc. You can declare arrays, structure members, and bit-fields of type long long. You can take the address of a long long, use a cast between long long and other types, and initialize a long long at the point where it is declared.

For converting to and from 64-bit integers, the scanf() and printf() families of functions have been enhanced to permit "ll" (ell ell) as a modifier to a conversion specifier of "d", "i", "o", "u", "x", or "X". There are also two new functions, strtoll() and strtoull(), which are the 64-bit equivalents of strtol() and strtoul().

The following sample program is an example of how to declare, use, and print a 64-bit integer using C/iX.

     /*  Compile on MPE/iX 6.5.            */
     /*  With CCXL use "-Aa +e" or "-Ae".  */
     /*  With c89 use "-Wc,+e".            */
     #include <stdio.h>
     main(void)
     {
        long long bignumber = 1234567654321LL;
        bignumber = bignumber * 1000000 + 123;
        printf("bignumber = %lld\n", bignumber);
     }




Compatibility Considerations for COBOL and C


FTP/iX Support for Large Files