Casting function ptrs

Chris Torek chris at trantor.umd.edu
Mon May 23 07:02:48 AEST 1988


In article <7330003 at hpcllz2.HP.COM> walter at hpcllz2.HP.COM (Walter Murray)
writes:
>... but I think the following has the virtue of being strictly
>conforming per the dpANS. ...
>
>struct funcs {char *name; void (*func)();};
>char *foo() {return "It worked!";};
>struct funcs f = {"foo",(void(*)())foo};

This is not strictly conforming, because the standard does not say
whether objects of type `void (*)()' are in any way compatible with
objects of type `char *(*)()'.  (It says very little about pointers
to functions, no matter what the return type of the function.  It
does not even say whether `void *' and `t (*)()' are compatible.)
Since, however, `char *' and `void *' are `the same', using a base
type of `void *(*)()' should work.

Most likely, pointers to any function, no matter what the return
type, will have the same format, but it would be nice to have some
guarantees.
-- 
In-Real-Life: Chris Torek, Univ of MD Computer Science, +1 301 454 7163
Domain: chris at mimsy.umd.edu		Path: ...!uunet!mimsy!chris



More information about the Comp.lang.c mailing list