HP C/iX Reference Manual (31506-90011)
158 Chapter9
HP C/iX Implementation Topics
Long and Short Pointers
contents of that member.
To produce a long pointer that points to the same object as a short pointer, you can use an
assignment statement. For example, after the assignment statement in the following C
code, long_ptr and short_ptr both point to the same object.
int ^long_ptr; /* long_ptr is a long pointer to an integer */
int *short_ptr; /* short_ptr is a short pointer to an integer */
.
.
.
long_ptr = short_ptr;
After the assignment statement, the low-order 32 bits of the long pointer are identical to
the original short pointer.
A short pointer may not be assigned the contents of a long pointer unless the long pointer
points to an object within the space of the current process.
You can apply the unary operator & to a long pointer to get the address of the pointer. The
resulting type of the operation &long_ptr is a short pointer. The following example assigns
the address of a long pointer to a variable declared as a short pointer to a long pointer.
int ^long_ptr;
int ^*sprt_to_lptr;
sptr_to_lptr = &long_ptr;
Note that the variable sptr_to_lptr must be declared as a short pointer to a long pointer
because the type of &long_ptr is a short pointer.
Standard pointer arithmetic and pointer subscripting may be applied to long pointers, but
only the low-order 32 bits are used and modiļ¬ed.
Comparison of long pointers using the relational operators <, <=, >, and >= compares only
the low order 32 bits, the offset portion. The high order 32 bits, the ID portion, are ignored.
Comparison of long pointers using the relational operators, == and !=, compares both the
low order 32 bits and the high order 32 bits.
Assignment of zero (NULL) to a long pointer assigns zero to the high order 32 bits and to
the low order 32 bits.
Casts can be applied to long pointers but you must observe the standard alignment
restrictions. For example, a long pointer to a character should not be cast to a long pointer
to an integer because an integer has more restrictive alignment requirements than a
character. Integers are aligned on 4 byte boundaries and characters are aligned on byte
boundaries.
There are no standard conversion rules for passing long pointer parameters to other
routines. Therefore, no implicit conversions are performed when these parameters are
passed. That is, short pointers are not converted to long pointers when a function call is
made, and vice versa.
All pointers passed to standard C library routines, including the heap manager routines,
must be short pointers.