
pointers to functions and pointers to void.
Quote:
> I had to look up in the standard today and there i found:
> 6.3.2.3 Pointers
> 1 A pointer to void may be converted to or from a pointer to any
> incomplete or object type. A pointer to any incomplete or object type
> ^^^^^^^^^^^^^^^^^^^^^^^^^
> may be converted to a pointer to void and back again; the result shall
> compare equal to the original pointer.
> So, if I read this correctly and there is no other clause which
> contradicts this I can't make a pointer to void point to a
> function and later convert the pointer back to a function pointer.
> Is this correct?
Yes. Pointers to data and pointers to code are entirely
different beasts in C. Any confusion between them is due entirely
to syntactic similarity, not to a semantic relation.
If you like, think of them as `long' and `double'. Both are
numeric, both can be used with `+' and `==' -- but they are
clearly not the same sort of thing, and you can lose information
by converting back and forth between them (in either direction,
usually).
Quote:
> So, AFAICS the only way to do this is to wrap the function pointer
> up in a struct. Anyone has any other ideas? The reason I ask is that
> I am using a generic datastructures and now I need to fill it with
> pointers...
"The only way to do this ..." I'm not sure precisely what "this"
is. Here's what you cannot do: make a `void*' point to a function.
(Nor can you make a function pointer point to an `int'.) However,
a function pointer itself is a data object, and you *can* make a
`void*' point to such a thing:
double (*f)(double) = sqrt;
void *vp = &f;
That is, "pointer to pointer to function" is perfectly all right.
Not sure whether this helps or hinders ...
--