Casting function ptrs
Walter Murray
walter at hpcllz2.HP.COM
Tue May 24 01:02:12 AEST 1988
chris at trantor.umd.edu (Chris Torek) writes:
>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....)
>
>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.
I was relying on the following statement from page 47 of the January
draft: "A pointer to a function of one type may be converted to a
pointer to a function of another type and back again; the result
shall compare equal to the original pointer."
That sounds to me like a guarantee. Did I read too much into it?
Walter Murray
All opinions expressed are my own.
More information about the Comp.lang.c
mailing list