(void *) to function pointer

Henry Spencer henry at zoo.toronto.edu
Sat Jan 12 05:01:43 AEST 1991


In article <1991Jan10.204613.27415 at ingres.Ingres.COM> jab at crane.Ingres.COM (jeff bowles) writes:
>>... 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...

Nope; function pointers are excluded... although there is a promise that
you can convert one flavor of function pointer to another without losing
information, so you don't really need `void *' for that -- all function
pointers are large enough to contain each other.

>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.

You can dereference a `void *' -- I had thought you couldn't, but it seems
to be permitted -- but the "value" you get is of type `void', which is
useless.

>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!")

`void *' and `char *' are required to use the same representation.  There
are too many places where library functions logically should take parameters
of type `void *' but historically take `char *'.
-- 
If the Space Shuttle was the answer,   | Henry Spencer at U of Toronto Zoology
what was the question?                 |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.std.c mailing list