legality of assignment of function to a void *.

Michael J Zehr tada at athena.mit.edu
Wed Nov 14 14:11:25 AEST 1990


In article <1990Nov13.174920.2235 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
>In article <1990Nov12.211511.2344 at batcomputer.tn.cornell.edu> lijewski at theory.tn.cornell.edu (Mike Lijewski) writes:
>>double f(double x) { return x * x; }
>>   void *ptr = f;
>
>Function pointers are a whole different universe from normal pointers, in
>principle.

I've tried to follow the new ansi rules pretty carefully and I wasn't
aware of this until recently when it was pointed out here(*).  My main
source of confusion was K&R2 (p. 199, "Any pointer may be converted to
type void * without loss of information.  If the result is converted
back to the original pointer type, the original pointer is recovered.")

This seems very misleading to me.  (Yes, I know that K&R2 is not the
official ANSI specification for C.)  Does anyone know if this was
something that was changed after K&R2 was written?  What about other
statements in K&R2 that are misleading or conflict with the standard?

-michael j zehr

(*) And fortunately or unfortunately, depending on how you look at it, I
do most of my work on a VAX, where a pointer is a pointer is a pointer,
so I never had problems with any code I wrote, nor did the compiler ever
complain.



More information about the Comp.std.c mailing list