[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

1.9.3 HP C Header Files

The header files distributed with OpenVMS support 64-bit pointers. Each function prototype whose signature contains a pointer is constructed to indicate the size of the pointer accepted.

A 32-bit pointer can be passed as an argument to functions that accept either a 32-bit or 64-bit pointer for that argument.

A 64-bit pointer, however, cannot be passed as an argument to a function that accepts a 32-bit pointer. Attempts to do this are diagnosed by the compiler with a MAYLOSEDATA message. The diagnostic message IMPLICITFUNC means the compiler can do no additional pointer-size validation for calls to that function. If this function is an HP C RTL function, refer to the reference section of this manual for the name of the header file that defines that function.

You might find the following pointer-size compiler diagnostics useful:

  • %CC-IMPLICITFUNC
    A function prototype was not found before using the specified function. The compiler and run-time system rely on prototype definitions to detect incorrect pointer-size usage. Failure to include the proper header files can lead to incorrect results and/or pointer truncation.
  • %CC-MAYLOSEDATA
    A truncation is necessary to do this operation. The operation could be passing a 64-bit pointer to a function that does not support a 64-bit pointer in the given context. It could also be a function returning a 64-bit pointer to a calling application that is trying to store that return value in a 32-bit pointer.
  • %CC-MAYHIDELOSS
    This message (when enabled) helps expose real MAYLOSEDATA messages that are being suppressed because of a cast operation. To enable this warning, compile with the qualifier /WARNINGS=ENABLE=MAYHIDELOSS.

1.9.4 Functions Affected

The HP C RTL accommodates applications that use only 32-bit pointers, only 64-bit pointers, or combinations of both. To use 64-bit memory, you must, at a minimum, recompile and relink an application. The amount of source code change required depends on the application itself, calls to other run-time libraries, and the combinations of pointer sizes used.

With respect to 64-bit pointer support, the functions in the HP C RTL fall into four categories:

  • Functions not impacted by choice of pointer size
  • Functions enhanced to accept either pointer size
  • Functions having a 32-bit and 64-bit implementation
  • Functions that accept only 32-bit pointers

From an application developer's perspective, the first two types of functions are the easiest to use in either a single- or mixed-pointer mode.

The third type requires no modifications when used in a single-pointer compilation, but might require source code changes when used in a mixed-pointer mode.

The fourth type requires careful attention whenever 64-bit pointers are used.

1.9.4.1 No Pointer-Size Impact

The choice of pointer size has no impact on a function if its prototype contains no pointer-related parameters or return values. The mathematical functions are good examples of this.

Even some functions in this category that do have pointers in their prototype are not impacted by pointer size. For example, strerror has the prototype:


char * strerror (int error_number); 

This function returns a pointer to a character string, but this string is allocated by the HP C RTL. As a result, to support both 32-bit and 64-bit applications, these types of pointers are guaranteed to fit in a 32-bit pointer.

1.9.4.2 Functions Accepting Both Pointer Sizes

The Alpha architecture supports 64-bit pointers. The OpenVMS Alpha calling standard specifies that all arguments are actually passed as 64-bit values. Before OpenVMS Alpha Version 7.0, all 32-bit addresses passed to procedures were sign-extended into this 64-bit parameter. The called function declared the parameters as 32-bit addresses, which caused the compiler to generate 32-bit instructions (such as LDL) to manipulate these parameters.

Many functions in the HP C RTL are enhanced to receive the full 64-bit address. For example, consider strlen :


size_t strlen (const char *string); 

The only pointer in this function is the character-string pointer. If the caller passes a 32-bit pointer, the function works with the sign-extended 64-bit address. If the caller passes a 64-bit address, the function works directly with that address.

The HP C RTL continues to have only a single entry point for functions in this category. There are no source-code changes required to add any of the four pointer-size options for functions of this type. The OpenVMS documentation refers to these functions as 64-bit friendly.

1.9.4.3 Functions with Two Implementations

There are many reasons why a function might need one implementation for 32-bit pointers and another for 64-bit pointers. Some of these reasons include:

  • The pointer size of the return value is the same size as the pointer size of one of the arguments. If the argument is 32 bits, the return value is 32 bits. If the argument is 64 bits, the return value is 64 bits.
  • One of the arguments is a pointer to an object whose size is pointer-size sensitive. To know how many bytes are being pointed to, the function must know if the code was compiled in 32-bit or 64-bit pointer-size mode.
  • The function returns the address of dynamically allocated memory. The memory is allocated in 32-bit space when compiled for 32-bit pointers, and is allocated in 64-bit space when compiled for 64-bit pointers.

From the application developer's point of view, there are three function prototypes for each of these functions. The <string.h> header file contains many functions whose return value is dependent upon the pointer size used as the first argument to the function call. For example, consider the memset function. The header file defines three entry points for this function:


void * memset   (void *memory_pointer, int character, size_t size); 
void *_memset32 (void *memory_pointer, int character, size_t size); 
void *_memset64 (void *memory_pointer, int character, size_t size); 

The first prototype is the function that your application would currently call if using this function. The compiler changes a call to memset into a call to either _memset32 when compiled with /POINTER_SIZE=32, or _memset64 when compiled with /POINTER_SIZE=64.

You can override this default behavior by directly calling either the 32-bit or the 64-bit form of the function. This accommodates applications using mixed-pointer sizes, regardless of the default pointer size specified with the /POINTER_SIZE qualifier.

If the application is compiled without specifying the /POINTER_SIZE qualifier, neither the 32-bit specific nor the 64-bit specific function prototypes are defined. In this case, the compiler automatically calls the 32-bit interface for all interfaces having dual implementations.

Table 1-5 shows the HP C RTL functions that have dual implementations to support 64-bit pointer size. When compiling with the /POINTER_SIZE qualifier, calls to the unmodified function names are changed to calls to the function interface that matches the pointer size specified on the qualifier.

Table 1-5 Functions with Dual Implementations
basename bsearch calloc catgets
ctermid cuserid dirname fgetname
fgets fgetws gcvt getcwd
getname getpwent getpwnam getpwnam_r
getpwuid getpwuid_r gets index
longname malloc mbsrtowcs memccpy
memchr memcpy memmove memset
mktemp mmap qsort readv
realloc rindex strcat strchr
strcpy strdup strncat strncpy
strpbrk strptime strrchr strsep
strstr strtod strtok strtok_r
strtol strtoll strtoq strtoul
strtoull strtouq tmpnam wcscat
wcschr wcscpy wcsncat wcsncpy
wcspbrk wcsrchr wcsrtombs wcsstr
wcstok wcstol wcstoul wcswcs
wmemchr wmemcpy wmemmove wmemset
writev glob globfree  

Table 1-6 shows the TCP/IP socket routines that have dual implementations to support 64-bit pointer size.

Table 1-6 Socket Routines with Dual Implementations
freeaddrinfo getaddrinfo
recvmsg sendmsg

1.9.4.4 Socket Transfers Greater than 64 KB

Starting with OpenVMS Version 8.3, support is added for socket transfers greater than 64 KB for the following socket routines:

send recv read
sendto recvfrom write
sendmsg recvmsg  

1.9.4.5 Functions Requiring Explicit use of 64-Bit Structures

Some functions require explicit use of 64-bit structures when compiling /POINTER_SIZE=LONG. This is necessary for functions that have recently had 64-bit support added to avoid unexpected runtime errors by inadvertently mixing 32-bit and 64-bit versions of structures.

Consider the following functions:


getaddrinfo        getpwnam 
freeaddrinfo       getpwnam_r 
getpwuid           getpwent 
sendmsg            getpwent_r 
recvmsg            

These functions previously offered 32-bit support only, even when compiled with /POINTER_SIZE=LONG. In order to preserve the previous behavior of 32-bit pointer support in those functions even when compiled with /POINTER_SIZE=LONG, these seven functions do not follow the normal convention for 32-bit and 64-bit support as documented in the previous section.

The following variants of these functions, and the corresponding structures they use, have been added to the C RTL to provide 64-bit support:


Function                        Structure 
--------                        --------- 
__getaddrinfo32                 __addrinfo32 
__getaddrinfo64                 __addrinfo64 
__freeaddrinfo32                __addrinfo32 
__freeaddrinfo64                __addrinfo64 
__recvmsg32                     __msghdr32 
__recvmsg64                     __msghdr64 
__sendmsg32                     __msghdr32 
__sendmsg64                     __msghdr64 
__32_getpwnam                   __passwd32 
__64_getpwnam                   __passwd64 
 
_getpwnam_r32 __passwd32 
_getpwnam_r64 __passwd64 
 
__32_getpwuid                   __passwd32 
__64_getpwuid                   __passwd64 
 
_getpwuid_r32  __passwd32 
_getpwuid_r64  __passwd64 
 
__32_getpwent                   __passwd32 
__64_getpwent                   __passwd64 

When compiling the standard versions of these functions, the following behavior occurs:

  • With /POINTER_SIZE=32 specified, the compiler converts the call to the 32-bit version of the function. For example, getaddrinfo is converted to __getaddrinfo32 .
  • With /POINTER_SIZE=64 specified, the compiler converts the call to the 64-bit version of the function. For example, getaddrinfo is converted to __getaddrinfo64 .
  • When the /POINTER_SIZE qualifier is not specified, neither the 32-bit-specific nor the 64-bit-specific function prototypes are defined.

However, a similar conversion of the corresponding structures does not occur for these functions. This behavior is necessary because these structures existed before OpenVMS Version 7.3-2 as 32-bit versions only, even when compiled with /POINTER_SIZE=LONG. Implicitly changing the size of the structure could result in unexpected run-time errors.

When compiling programs that use the standard version of these functions for 64-bit support, you must use the 64-bit-specific definition of the related structure. With /POINTER_SIZE=64 specified, compiling a program with the standard function name and standard structure definition will result in compiler PTRMISMATCH warning messages.

For example, the following program uses the getaddrinfo and freeaddrinfo routines, along with the standard definition of the addrinfo structure. Compiling this program results in the warning messages shown:


$ type test.c 
#include <netdb.h> 
 
int main () 
{ 
    struct addrinfo *ai; 
 
    getaddrinfo ("althea", 0, 0, &ai); 
    freeaddrinfo (ai); 
    return 0; 
} 
 
$ cc /pointer_size=64 TEST.C 
 
    getaddrinfo ("althea", 0, 0, &ai); 
....^ 
%CC-W-PTRMISMATCH, In this statement, the referenced type of the pointer value 
"&ai" is "long pointer to struct addrinfo", which is not compatible with "long 
pointer to struct __addrinfo64". 
at line number 7 in file TEST.C;1 
 
    freeaddrinfo (ai); 
....^ 
%CC-W-PTRMISMATCH, In this statement, the referenced type of the pointer value 
"ai" is "struct addrinfo", which is not compatible with "struct __addrinfo64". 
at line number 8 in file TEST.C;1 
$ 

When compiling for 64 bits, you need to use the 64-bit-specific version of the related structure. In the previous example, the declaration of the ai structure could be changed to the following:


struct __addrinfo64 *ai; 

Or, to provide flexibility between 32-bit and 64-bit compilations, the ai structure could be declared as follows:


#if __INITIAL_POINTER_SIZE == 64 
    struct __addrinfo64 *ai; 
#else 
    struct __addrinfo32 *ai; 
#endif 

1.9.4.6 Functions Restricted to 32-Bit Pointers

A few functions in the HP C RTL do not support 64-bit pointers. If you try to pass a 64-bit pointer to one of these functions, the compiler generates a %CC-W-MAYLOSEDATA warning. Applications compiled with /POINTER_SIZE=64 might need to be modified to avoid passing 64-bit pointers to these functions.

Table 1-7 shows the functions restricted to using 32-bit pointers. The HP C RTL offers no 64-bit support for these functions. You must ensure that only 32-bit pointers are used with these functions.

Table 1-7 Functions Restricted to 32-Bit Pointers
atexit getopt putenv
execv iconv setbuf
execve initstate setstate
execvp ioctl setvbuf

Table 1-8 shows functions that make callbacks to user-supplied functions as part of processing that function call. The callback procedures are not passed 64-bit pointers.

Table 1-8 Callbacks that Pass Only 32-Bit Pointers
decc$from_vms decc$to_vms
ftw tputs

1.9.5 Reading Header Files

This section introduces the pointer-size manipulations used in the HP C RTL header files. Use the following examples to become more proficient in reading these header files and to help modify your own header files.


Examples

#1

: 
#if __INITIAL_POINTER_SIZE (1)
#   if (__VMS_VER < 70000000) || !defined __ALPHA (2)
#      error " Pointer size usage not permitted before OpenVMS Alpha V7.0" 
#   endif 
#   pragma __pointer_size __save (3)
#   pragma __pointer_size 32 (4)
#endif 
: 
: 
#if __INITIAL_POINTER_SIZE (5)
#   pragma __pointer_size 64 
#endif 
: 
: 
#if __INITIAL_POINTER_SIZE (6)
#   pragma __pointer_size __restore 
#endif 
: 
 
 
      

All HP C compilers that support the /POINTER_SIZE qualifier predefine the __INITIAL_POINTER_SIZE macro. The HP C RTL header files take advantage of the ANSI rule that if a macro is not defined, it has an implicit value of 0.

The macro is defined as 32 or 64 when the /POINTER_SIZE qualifier is used. It is defined as 0 if the qualifier is not used. The statement at (1) can be read as "if the user has specified either /POINTER_SIZE=32 or /POINTER_SIZE=64 on the command line".

The C compiler is supported on many OpenVMS versions. The lines at (2) generate an error message if the target of the compilation is one that does not support 64-bit pointers.

A header file cannot assume anything about the actual pointer-size context in effect at the time the header file is included. Furthermore, the HP C compiler offers only the __INITIAL_POINTER_SIZE macro and a mechanism to change the pointer size, but not a way to determine the current pointer size.

All header files that have a dependency on pointer sizes are responsible for saving (3), initializing (4), altering (5), and restoring (6) the pointer-size context.

#2

: 
#ifndef __CHAR_PTR32 (1)
#   define __CHAR_PTR32 1 
    typedef char * __char_ptr32; 
    typedef const char * __const_char_ptr32; 
#endif 
: 
: 
#if __INITIAL_POINTER_SIZE 
#   pragma __pointer_size 64 
#endif 
: 
: 
#ifndef __CHAR_PTR64 (2)
#   define __CHAR_PTR64 1 
    typedef char * __char_ptr64; 
    typedef const char * __const_char_ptr64; 
#endif 
: 
 
 
      

Some function prototypes need to refer to a 32-bit pointer when in a 64-bit pointer-size context. Other function prototypes need to refer to a 64-bit pointer when in a 32-bit pointer-size context.

HP C binds the pointer size used in a typedef at the time the typedef is made. Assuming this header file is compiled with no /POINTER_SIZE qualifier or with /POINTER_SIZE=SHORT, the typedef declaration of __char_ptr32 (1) is made in a 32-bit context. The typedef declaration of __char_ptr64 (2) is made in a 64-bit context.

#3

: 
#if __INITIAL_POINTER_SIZE 
#   if (__VMS_VER < 70000000) || !defined __ALPHA 
#      error " Pointer size usage not permitted before OpenVMS Alpha V7.0" 
#   endif 
#   pragma __pointer_size __save 
#   pragma __pointer_size 32 
#endif 
: 
(1)
: 
#if __INITIAL_POINTER_SIZE (2)
#   pragma __pointer_size 64 
#endif 
: 
(3)
: 
int abs (int __j); (4)
: 
__char_ptr32 strerror (int __errnum); (5)
: 
 
 
      

Before declaring function prototypes that support 64-bit pointers, the pointer context is changed (2) from 32-bit pointers to 64-bit pointers.

Functions restricted to 32-bit pointers are placed in the 32-bit pointer context section (1) of the header file. All other functions are placed in the 64-bit context section (3) of the header file.

Functions that have no pointer-size impact ((4) and (5)) are located in the 64-bit section. Functions that have no pointer-size impact except for a 32-bit address return value (5) are also in the 64-bit section, and use the 32-bit specific typedef s previously discussed.

#4

: 
#if __INITIAL_POINTER_SIZE 
#   pragma __pointer_size 64 
#endif 
: 
: 
#if __INITIAL_POINTER_SIZE == 32 (1)
#   pragma __pointer_size 32 
#endif 
: 
char *strcat (char *__s1, __const_char_ptr64 __s2); (2)
: 
#if __INITIAL_POINTER_SIZE 
#   pragma __pointer_size 32 
    : 
    char *_strcat32  (char *__s1, __const_char_ptr64 __s2); (3)
    : 
#   pragma __pointer_size 64 
    : 
    char *_strcat64  (char *__s1, const char *__s2); (4)
    : 
#endif 
: 
 
 
      

This example shows declarations of functions that have both a 32-bit and 64-bit implementation. These declarations are located in the 64-bit section of the header file.


Previous Next Contents Index