function casting
Blair P. Houghton
bph at buengc.BU.EDU
Sun Apr 30 18:59:05 AEST 1989
In article <12481 at umn-cs.CS.UMN.EDU> clark at umn-cs.CS.UMN.EDU (Robert P. Clark) writes:
>
>main()
>{
> int (*f)();
It's alright, so far...
> char *foo();
>
>
> f = ((*int)())foo(); /* foo returns char*, but I know this is */
> /* really an address of a function */
Bad declaration-to-cast conversion...
You want merely to remove the identifier when doing a cast, rather
that rearranging anything.
The declaration
int (*f)();
becomes a cast, therefore, by excising the "f" and the ";" and
pre-/ap-pending "(" and ")".
f = ( int (*)() ) foo();
>}
There are programs out there that do it.
If you really want to know, by doing
f = ((*int)())...
You're trying to call a function pointed-to by a thing called 'int'
which is a C keyword, and therefore will generate all sorts of syntactical
trouble in the situation you've placed it.
PLUG ALERT!
Andrew Koenig's _C Traps and Pitfalls_ handles this about as well
as it can be handled...
GO BACK TO YOUR HOMES, THERE'S NOTHING LEFT TO BE BOUGHT, HERE...
--Blair
"Do I get a free copy of
ed. 2, now, huh, Andy, huh,
do I do I do I ?? :-)"
More information about the Comp.lang.c
mailing list