Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX 64-bit Porting and Transition Guide: HP 9000 Computers > Chapter 5 Writing Portable Code

Guidelines for Using <inttypes.h>

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

When porting to 64-bit mode, you should only use 64-bit data types when they are required. This data type may not be processed efficiently on some platforms. Programs may run slower and executable file sizes may be bigger.

Here are additional guidelines:

  • Use int32_t for integers that must be 32 bits in length on 64-bit systems in order for programs to work correctly.

    Because <inttypes.h> is available on both 32-bit and 64-bit HP-UX platforms, int32_t works in both environments.

  • Use the smallest integral type possible in order to control the size of the application.

  • Use the intfastn_t data types for counters and counter loops that need to be fast due to frequent expression evaluations (such as incrementing).

  • Use the constant that matches the integer type definition.

    For example, use the constant UINT64_FAST_MAX with uint_fast64_t. Do not use INT_MAX or UINT_MAX with uint_fast64_t.

  • Use intmax_t or uintmax_t for items that must be the largest available integral type as specified by the compiler.

    The sizes of these data types may change in a future release, but they will always be the largest integral type supported on the platform, regardless of possible performance implications.

  • Limit the use of x64_t data types:

    • These types cannot automatically take advantage of potentially higher limits for future integral sizes.

    • Older 32-bit systems may not have a 64-bit integral data type. Therefore, int64_t and uint64_t data types may need to be protected by #ifdefs if the source code is shared between 64-bit and older 32-bit systems.

  • Convert long long to int64_t. Convert unsigned long long to uint64_t.

  • End user APIs reflect the data types defined by standards such as X/Open, POSIX.2, or legacy HP definitions. They will not cause source level incompatibilities.

    The function prototype looks the same in any integral data type model. Therefore, your application will be protected when there are changes to the underlying size of data types. For example, the function prototype for lseek():

          off_t lseek(int fildes, off_t offset, int whence);
    int fseek(FILE *stream, long int offset, int whence);

    looks the same on a 32-bit or 64-bit system.

  • Use the same type definition names supported by the API definition. For example, use off_t in your code offsets. Do not assume off_t is an int, long, or any other data type.

  • Data declarations related to API parameters or return values should be of the same consistent data definition as defined by the function prototype.

  • Integral types (for example, long) that must be 32 bits on a 32-bit system and 64 bits on a 64-bit system can be left as long. These types will automatically be declared with the correct size.

  • Use scalable masks with scalable typedefs and fixed size masks with fixed size typedefs. (See “Using Portable Bit Masks ” for examples.)

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1998 Hewlett-Packard Development Company, L.P.