Seebs <usenet-nos...@seebs.net> writes: > On 2010-09-30, Paul Rubin <no.em...@nospam.invalid> wrote: >> int maximum(int a, int b); >> >> int foo() { >> int (*barf)() = maximum; >> return barf(3); >> } > >> This compiles fine for me. Where is the cast? > > On the first line of code inside foo().
Look again; there's no cast in foo(). That first line declare barf as an object of type "pointer to function returning int", or more precisely, "pointer to function with an unspecified but fixed number and type of parameters returning int" (i.e., an old-style non-prototype declaration, still legal but deprecated in both C90 and C99). It then initializes it to point to the "maximum" function. I *think* the types are sufficiently "compatible" (not necessarily using that word the same way the standard does) for the initialization to be valid and well defined. I might check the standard later. It would have been better to use a prototype (for those of you in groups other than comp.lang.c, that's a function declaration that specifies the types of any parameters): int (*barf)(int, int) = maximum; IMHO it's better to use prototypes consistently than to figure out the rules for interactions between prototyped vs. non-prototyped function declarations. [...] -- Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" -- http://mail.python.org/mailman/listinfo/python-list