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 Reference > P

portal(5)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

portal — a "window to the future" for applications

SYNOPSIS

#include <sys/portal.h>

DESCRIPTION

This header file is a "window to the future" for applications. It will help you to:

  • Write code that is portable across 32-bit and 64-bit systems,

  • Avoid undocumented assumptions about sizes of integral types,

  • Write portable code that needs to be explicit about the sizes of integral types,

  • Write code that is portable to a platform which has different sizes of integral types, and

  • Share frequently used macros that are portable across 32-bit and 64-bit systems.

In addition to the macros defined in this file, it includes the header files limits.h (see limits(5)) and inttypes.h (see inttypes(5)).

The following macros are defined in sys/portal.h:

SET_MASK_BIT( bit_num, type)

This macro can be used to create a mask that has one bit set. bit_num is the position of the bit to set, and type is the data type of the mask. A -1 is returned in the case of overflow or underflow.

SET_MASK_BIT_LOOP(mask, bit_num, type)

This macro can be used to set a bit in a mask. mask is the current value of the mask, bit_num is the position of the bit to set, and type is the data type of the mask.

SIGN_BIT(type)

This macro can be used to return the bit position of the sign bit for the specified data type. type is the data type for which to return the position of the sign bit.

SIGN_BIT_MASK(type)

This macro can be used to return a mask for the sign bit for the specified data type. type is the data type for which to return the sign bit mask.

SIGN_EXTEND(value, old_type, new_type)

This macro can be used to do a sign extension from one data type to another. value is the current value that is to be sign-extended. old_type is the current data type of value and new_type is the new data type of value.

TEST_ENDIAN(endian)

This macro can be used to check if code has been compiled big or little endian. endian is an integer in which the result will be returned.

The following macros can be used for print formatting and scan formatting of values of data types that can change in size based upon the compilation flag _FILE_OFFSET_BITS. Examples of such data types are off_t and fpos_t.

PRIdF64 d print formatting option for a 32-bit or 64-bit size value. PRIoF64 o print formatting option for a 32-bit or 64-bit size value. PRIxF64 x print formatting option for a 32-bit or 64-bit size value. PRIuF64 u print formatting option for a 32-bit or 64-bit size value. SCNdF64 d scan formatting option for a 32-bit or 64-bit size value. SCNoF64 o scan formatting option for a 32-bit or 64-bit size value. SCNxF64 x scan formatting option for a 32-bit or 64-bit size value. SCNuF64 u scan formatting option for a 32-bit or 64-bit size value.

EXAMPLES

The SET_MASK_BIT macro in the following example will turn on the high bit in a 64-bit integer.

SET_MASK_BIT(SIGN_BIT(int64_t), int64_t)

The SET_MASK_BIT macro in the following example will be used to turn on all bits except the sign bit in a 32-bit integer.

~SET_MASK_BIT(SIGN_BIT(int32_t), int32_t)

The SET_MASK_BIT_LOOP macro in the following example will turn on the three least significant bits of the maximum integer.

int i; intmax_t mask = 0; for (i = 0; i < 3; i++) { SET_MASK_BIT_LOOP(mask, i, intmax_t); }

The SIGN_BIT macro in the following example will return the position of the sign bit in a 32-bit integer.

SIGN_BIT(int32_t)

The SIGN_BIT_MASK macro in the following example will return a sign bit mask for a 32-bit integer.

SIGN_BIT_MASK(int32_t)

The SIGN_EXTEND macro in the following example will convert the 8-bit integer stored in a char data type to a 64-bit integer and correctly extend the sign.

char c; int64_t i; i = SIGN_EXTEND(c, char, int64_t);

The TEST_ENDIAN macro in the following example will store a 1 in endian if the compilation was big endian; otherwise, it will store a 0 in endian.

int endian; TEST_ENDIAN(endian); if (endian == 0) printf("This a little endian system\n"); if (endian == 1) printf("This a big endian system\n");

AUTHOR

portal.h was developed by HP.

FILES

/usr/include/sys/portal.h

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