C/C++ Programmer's Guide (G06.25+)
System-Level Programming
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
9-3
Passing Pointers to Constants Between Code
Spaces
Example
The following example shows valid uses of the CSADDR pragma to pass pointers to
constants between code spaces:
#pragma env library
#pragma csaddr
#pragma xmem
void foo( const void * );
main()
{
const struct S { int i,j,k; } s = { 10, 20, 30 };
const struct S *sp;
foo( "This is a test" ); /* 15 bytes copied and passed */
foo( &s ); /* 6 bytes copied and passed */
sp = &s;
A pointer variable to the code space cannot be initialized. Explicit assignment or
conversion to array type is recommended. For example, the following function results
in an error because name is an array of pointers and thus cannot be initialized:
#pragma env library
#include <stringh>
int find_kevin(void)
{
const char *name[] =
{"linda", "don", "kevin"};
const int LAST_NAME = 3;
const char *p;
int i = 0;
for (p = name; i <= LAST_NAME ; i++, p = &name[i])
if (!strcmp(p, "kevin"))
return TRUE;
return FALSE;
}
The previous function can be made valid by converting name to a two dimensional
array without making any other changes, as shown in the following code:
#pragma env library
#pragma inline
#include <stringh>
int find_kevin(void)
{
const char name[][6] =
{{"linda"}, {"don"}, {"kevin"}};
const int LAST_NAME = 3;
const char *p;
int i = 0;