(void *) to function pointer

jeff bowles jab at ingres.com
Fri Jan 11 07:46:13 AEST 1991


In article <1991Jan9.000809.9152 at brolga.cc.uq.oz.au> gottsc at citrus.citr.uq.oz.au (John Gottsc) writes:
>
>can anybody tell me what the ANSI C standards state regarding conversion
>between a (void *) and a function pointer (i.e. is this type of
>conversion possible in ANSI C)? 
>
>We have a machine (a UNISYS 1100) on which this type of conversion 
>is impossible, and I have two documents
>("Notes on Writing Portable Programs in C" by Dolenc et al, and 
>"Recommended C style and Coding Standards") which state that a (void *)
>is only guaranteed to be large enough to hold a pointer to any *data*
>object) and is not suitable for a generic function pointer.

It was my impression that a "void *" had to be large enough to contain
any other kind of pointer, and that there were no rules that said that
you had to be able to dereference a "void *" without converting it to
some other pointer type first.

For example, say a "pointer-to-function" would need to contain a
segment number in addition to the address of the first instruction of the
function. An call through this sort of pointer might mean "pry the segment
number out of the pointer, do three hand-stands to map in that segment,
then pry the address of the first instruction of the function and do the
special procedure call to jump to that routine."  This might take 80-bits
or 160-bits to store all the information to call a function indirectly,
so that "sizeof" for a "pointer-to-function" is a pretty big number.

Then "void *" would have to be at least that large. There is no guarantee
that conversion to any other type of pointer and back again retains all
information. (I heard that they put in a hack so this would be true for
"char *" also, but "say it ain't so!")

	Jeff Bowles
--
"A wise man turneth away politicians." (or something like that)



More information about the Comp.std.c mailing list