Xref: utzoo comp.lang.c:27800 gnu.gcc:1549 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!spdcc!merk!alliant!linus!nixbur!nixpbe!unido!mikros!mwtech!martin From: martin@mwtech.UUCP (Martin Weitzel) Newsgroups: comp.lang.c,gnu.gcc Subject: Re: How do I cast to "pointer to function returning int" ? Message-ID: <714@mwtech.UUCP> Date: 11 Apr 90 12:05:28 GMT References: <6090.2621f6c2@csv.viccol.edu.au> <18834@duke.cs.duke.edu> Reply-To: martin@mwtech.UUCP (Martin Weitzel) Organization: MIKROS Systemware, Darmstadt/W-Germany Lines: 34 In article <18834@duke.cs.duke.edu> drh@romeo.UUCP (D. Richard Hipp) writes: :In article <6090.2621f6c2@csv.viccol.edu.au> timcc@csv.viccol.edu.au writes: :>struct foo { :> char *name ; :> int (*function) () ; :> } ; :> :>struct foo foo_table[] = { :> "bar", (int * ()) bar, :> "blurfl", (int * ()) blurfl, :> "frobjitz", (int * ()) frobjitz, :> } ; : :The typecast (int *()) is for "function returning pointer to integer". :To get "pointer to function returning integer" use (int (*)()). : :The rule is this: operators on the right hand side bind tighter than :operators on the left hand side. Thus "()" binds tighter than "*". :You want the "*" to bind closest, so the extra parenthesis are required. Or, if you want an easy 'step-to-step' procedure, do it as follows: 1) write a declaration for some object 'foo', so that 'foo' has the desired type. 2) avoid all unnecessary brackets (here the above rule comes into play, that '()' and '[]' on the right bind more tightly than '*' on the left; use brackets like in expressions, if you want other binding) 3) cancel the name 'foo' and enclose what remains in brackets 4) after half an hour take the freshly baked cast out of the oven and enjoy! -- Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83