OSF DCE Application Development Guide--Introduction and Style Guide

OSF DCE Application Development Guide—Introduction and Style Guide
The server manager code to implement this points the client pointer to the beginning of
the array and then increments it once:
void
ptr_test1(
handle_t h,
num_ptr *client_ptr,
num_array client_array,
error_status_t *status
)
{
*status = 0;
*client_ptr = client_array;
++(*client_ptr);
}
On return, the client’s version of the pointer will point to memory that holds the second
element of the array. It will not point to the array itself, however. The client code
demonstrates this:
num_ptr client_ptr = NULL;
num_array client_array = {25, 50, 75};
ptr_test1(binding_h, &client_ptr, client_array, &status);
/*
* The test function pointed the client pointer to the
* second array element. On return, this points to memory
* that holds this value.
*/
printf("Client pointer points to %i0, *client_ptr);
/* However, if we now increment the pointer, it
* points to unintialized memory. This shows the
* limits of mirroring.
* *** WARNING: You may dump core here !! ***
*/
client_ptr++;
printf("Client pointer now points to %i0, *client_ptr);
What happens here is that the client stub allocates space for the new referent of
client_ptr when the call returns. This space now holds the value in the second element
of the array. The pointer no longer points to the original array but to this newly allocated
space. You can see this clearly when the client attempts to increment the pointer.
Instead of pointing to the third element of the array, it points to some undetermined place
in memory, and the client may fail when it tries to dereference the pointer.
As an exercise, you could change the code to declare a pointer to the num_array defined
type rather than to an integer. Then you could have the server manager point this to the
6 14 Tandem Computers Incorporated 124246