![]() |
Software > OpenVMS Systems > Documentation > 731final > 5841 ![]() HP OpenVMS Systems Documentation |
![]() |
OpenVMS Programming Concepts Manual
11.7.2 Obtaining 64-Bit Pointers to MemoryThe Compaq C RTL has many functions that return pointers to newly allocated memory. In each of these functions, the application owns the memory pointed to and is responsible for freeing that memory. Functions that allocate memory are: malloc Each of these functions has a 32-bit and 64-bit implementation. When you use the /POINTER_SIZE qualifier, the following functions can also be called: _malloc32 , _malloc64 When you specify /POINTER_SIZE=32, all malloc calls default to _malloc32 . When you specify /POINTER_SIZE=64, all malloc calls default to _malloc64 . Regardless of whether the application calls a 32-bit or 64-bit memory allocation routine, there is still a single free function. This function accepts either pointer size. Note that the memory allocation functions are the only ones that return pointers to 64-bit memory. All Compaq C RTL structure pointers returned to the calling application (such as a FILE, WINDOW, or DIR) are always 32-bit pointers. This allows both 32-bit and 64-bit callers to pass these structure pointers within the application. 11.7.3 Compaq C Header FilesThe header files distributed with Compaq C Version 5.2 and higher 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. You might find the following pointer-size compiler diagnostics useful:
11.7.4 Functions AffectedThe Compaq C RTL shipped with OpenVMS Alpha Version 7.0 accommodates applications that use only 32-bit pointers, only 64-bit pointers, or a combination 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 Compaq C RTL fall into four categories:
From an application developer's perspective, the first two types of functions are the easiest to use in either a single-pointer 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. 11.7.4.1 No Pointer-Size ImpactThe 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:
This function returns a pointer to a character string, but this string is allocated by the Compaq 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. 11.7.4.2 Functions Accepting Both Pointer SizesThe 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 Compaq C RTL are enhanced to receive the full 64-bit address. For example, consider strlen :
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 with that address directly. The Compaq 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. 11.7.4.3 Functions with Two ImplementationsThere are many reasons why a function might need two implementations---one for 32-bit pointers, the other for 64-bit pointers. Some of these reasons include:
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:
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 /POINTER_SIZE=32, or _memset64 when compiled /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. Note that 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 11-4 shows the Compaq C RTL functions that have dual implementations in support of 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 with the qualifier.
11.7.4.4 Functions Restricted to 32-Bit PointersSome functions in the Compaq 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 11-5 shows the functions restricted to using 32-bit pointers. The Compaq C RTL offers no 64-bit support for these functions. You must ensure that only 32-bit pointers are used with these functions.
Table 11-6 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.
11.7.5 Reading Header FilesThis section introduces the pointer-size manipulations used in the Compaq C RTL header files. Use the following examples to become more comfortable reading these header files and to help modify your own header files. Examples
|