Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

CC /POINTER_SIZE = 32 v. <stdlib.h> -- %CC-I-FUNCMIXPTR

 
Steven Schweda
Honored Contributor

CC /POINTER_SIZE = 32 v. <stdlib.h> -- %CC-I-FUNCMIXPTR

I don't mean to nit-pick (not much, anyway),
but why am I (acting as an informal proxy for
the OpenSSL organization) getting these
annoying informational messages from what
should be identical situations? (Shouldn't
they be?)

alp $ type funcmixptr.c
#include

static void *(*realloc_func)(void *, size_t) = realloc;

static void (*free_func)(void *) = free;

int main( int argc, char **argv) {}

Case 1. No complaints:
alp $ cc /noobject /nopointer_size funcmixptr.c

Case 2. Annoying complaints:
alp $ cc /noobject /pointer_size = 32 funcmixptr.c

static void *(*realloc_func)(void *, size_t) = realloc;
..................................^
%CC-I-FUNCMIXPTR, In the initializer for realloc_func, function types differ bec
ause this declaration specifies "short pointer" and a previous declaration speci
fies "long pointer".
at line number 3 in file ALP$DKA0:[SMS.IZ]funcmixptr.c;4

static void (*free_func)(void *) = free;
..............................^
%CC-I-FUNCMIXPTR, In the initializer for free_func, function types differ becaus
e this declaration specifies "short pointer" and a previous declaration specifie
s "long pointer".
at line number 5 in file ALP$DKA0:[SMS.IZ]funcmixptr.c;4


The pointers are all supposed to be 32-bit in
both cases, aren't they? (Who writes these
header files?)

Who can explain why this is all my fault,
and/or why this is how it's supposed to work?
9 REPLIES 9
Steven Schweda
Honored Contributor

Re: CC /POINTER_SIZE = 32 v. <stdlib.h> -- %CC-I-FUNCMIXPTR

Oh, yeah...

alp $ cc /version
HP C V7.3-009 on OpenVMS Alpha V8.3

IT $ cc /version
HP C V7.3-019 on OpenVMS IA64 V8.3-1H1
Hoff
Honored Contributor

Re: CC /POINTER_SIZE = 32 v. <stdlib.h> -- %CC-I-FUNCMIXPTR

The following comment is based on looking at stdlib.h from this configuration:

HP C V7.1-015 on OpenVMS Alpha V8.3

This line:

void * realloc (__void_ptr64 __ptr, __size_t __size);

looks like it might be a bug, based on the other calls around it.

Switching the line over to this:

void * realloc (void *_ptr, __size_t __size);

fixes the first diagnostic. Here's the line and the replacement line in context:

void * calloc (__size_t __nmemb, __size_t __size);
void * malloc (__size_t __size);
// void * realloc (__void_ptr64 __ptr, __size_t __size);
void * realloc (void *_ptr, __size_t __size);
void * bsearch (const void *, const void *, __size_t, __size_t, int (*__comp
ar)(const void *, const void *));
void qsort (void *, __size_t, __size_t, int (*__compar)(const void *, co
nst void *));


This line:

void free (void *__nptr);

is always declared as a 64-bit function, irrespective of the requested pointer length; just as soon as you include /pointer_size on the command, this becomes a 64-bit pointer. This based on the preceding

# pragma __pointer_size 64

And that also too seems it might be a bug, too.

The C language gurus will probably need to have a look at this one.
Craig A Berry
Honored Contributor

Re: CC /POINTER_SIZE = 32 v. <stdlib.h> -- %CC-I-FUNCMIXPTR

$ help cc/pointer_size says


Specifying /POINTER_SIZE=32 directs the compiler to assume that all
pointers are 32-bit pointers. But unlike the default of
/NOPOINTER_SIZE, /POINTER_SIZE=32 enables use of the #pragma
pointer_size long and #pragma pointer_size short preprocessor
directives to control pointer size throughout your program.


and those pragmas are in use in stdlib.h. It looks as though giving a value to the /POINTER_SIZE qualifier enables the __INITIAL_POINTER_SIZE macro, but untangling the rest of what's going on in that header is more than I have time for at the moment. I'd be sure to compile with /list/show=(expansion,include) to see what prototypes and pragmas you're actually getting.
Steven Schweda
Honored Contributor

Re: CC /POINTER_SIZE = 32 v. <stdlib.h> -- %CC-I-FUNCMIXPTR

> The following comment [...]

Yup. That's how it looks around here, too.

> The C language gurus will probably need to
> have a look at this one.

I've sent a pointer off to
OpenVMS.Programs@hp, just in case it might
help.


> $ help cc/pointer_size says

I read it. Hence my complaint.

> [...] to see what prototypes and pragmas
> you're actually getting.

Not very interesting, actually. I'm getting
only what's in the system header files
(modules), so whatever happens is not my
fault (I claim). The complaints are only
"-I-", so the build procedure is unaffected,
and the stuff works, so they don't seem to
matter much, but I (for one) would be happier
if the system headers didn't give the
compiler indigestion on otherwise
harmless-looking code, depending on the
harmless-looking compiler options.
Lucifer Megacruel
Valued Contributor

Re: CC /POINTER_SIZE = 32 v. <stdlib.h> -- %CC-I-FUNCMIXPTR

Hi ,

I would point you Section 1.10 of the the OpenVMS CRTL manual where there is a good discussion of mixing and 32bit and 64 bit pointers in the same application . free is a function that accepts both 32bit and 64 bit pointers . In order to allocate 32 bit memory in 64 bit application you need to call _malloc32. So if you if you do

void *(*realloc_func)(void *, size_t) = _realloc32;

it will silence the compiler when compiled with /POINTER=32. There is nothing you can do to silence free , since it is designed to accept both 32 bit and 64 bit pointers. As a good programmer, I understand that it is annoying to find warnings when it is not your fault.

One caveat you need to be careful though:
The the 32 bit and 64 bit malloc calls corresponding lib$ routines in librtl. There is no communication between these 32 bit and 64 bit librtl routines. 32 bit routines allocate memory from P0 and 64 bit from P2 space. So if you allocate memory in 32bit space and use realloc64 to copy it will fail.
But in the program given below, if you remove the first line , you will find that librtl allocates the requested size. But this is because no malloc64 is not yet called, so it thinks it is a fresh allocation.

complile with /POINTER=LONG
#include
#include

int main()
{
char *test = malloc(1); /* remove this line to see the issue */
__char_ptr32 c1 = (__char_ptr32)_malloc32(1);
*c1 = 'x';
printf("%08llx : <%c>\n", c1, *c1);
char* c2 = (char*)realloc(c1, 10000); /* force reallocation */

if( c2 == NULL)
{
printf(" Realloc fails !" );
}
return EXIT_FAILURE;
}

--Lucifer
"To Denouce the Evils of Truth and Love. To cause may hem and destruction and necromancy , Lucifer is here"