%p and different pointer representations

Ex-God c08_d103 at jhunix.HCF.JHU.EDU
Thu Mar 2 07:49:49 AEST 1989


I need a few things clarified; I don't have a copy of the standard,
and a few people have said mutually contradictory things.  So tell me
if the following is right:

Any object or incomplete pointer fits in (void *).
Any object or inconplete pointer fits in (char *).
Any function pointer fits in any other function pointer.
Function pointers do not have to fit into (void *) (or vice-versa).

Also, how's this for a solution:
#if sizeof (void *) > sizeof (void (*)())
#define generic_ptr (void *)
#else
#define generic_ptr (void (*)())
#endif
Then use generic_ptr instead of void *, and any pointer type
(including pointers to functions) will fit (as long as you remember to
cast everything you assign).

I can see one problem with this solution -- if, for example, an
implementation stored functions in one area and objects in another and
there was no pointer type that could point to either.  I suppose you
could use a union or something....

I guess the best solution would have been to continue using char * as
a generic object pointer, to make all function pointer the same size,
and to make void * big enough to hold either.  Someone should have
thought of that earlier, I guess....

     -- Andrew Barnert (Andy Social/Andy Christ/Andy Matter/ex-God)
        ins_balb at jhunix/ins_balb at jhuvms/c08_d103 at jhunix
The opinions expressed in this message are yours.
"If you can't stand the Big Chill, burn down the freezer." -- Jello Biafra



More information about the Comp.lang.c mailing list