Path: utzoo!utgpu!attcan!uunet!mtxinu!ed From: ed@mtxinu.UUCP (Ed Gould) Newsgroups: comp.sys.mac.programmer Subject: Re: Arrays of functions in THINK C Keywords: Why does this not work? Message-ID: <633@mtxinu.UUCP> Date: 8 Aug 88 23:27:10 GMT References: <2884@mit-amt.MEDIA.MIT.EDU> <9651@dartvax.Dartmouth.EDU> <1131@aimt.UUCP> Reply-To: ed@mtxinu.UUCP (Ed Gould) Organization: mt Xinu, Berkeley Lines: 62 >Actually, K&R does say something about it. On page 182 (section 7.1 >of appendix A) it says: > A function call is a primary expression followed by parentheses > containing a possibly empty, comma-separated list of expressions > which constitute the actual arguments to the function. The > primary expression must be of type "function returning ...", and > the result of the function call is of type "...". >At least I take this to mean that the primary expression shouldn't be >of type "pointer to function returning ...". Funny, it's the unix >compilers that are broken in this case. Of course my "analysis" may >be flawed. Your analysis is slightly flawed. "function returning ..." can mean, for example, function returning pointer to ... A primary expression that is a function call is not a pointer; it is a reference to a pointer. Consider char *f(); char *(*g)(); main() { g = f; f(); g(); (*g)(); } The declarations are for "f", a function returning pointer to char, and "g", a pointer to a function returning pointer to char. There are three function calls in this program. The first, "f()", is the usual sort of call: "f" is the name of a function. The second, "g()" is a misleading form: It looks like "g" is the name of a function, but really it's an implicit dereference (this form may not be alliwed by ANSI - I'm not sure). The third is an explicit dereference of a pointer to a function. To get back to the original question about arrays of functions, they are not allowed so far as I know. Arrays of pointers to functions are. Consider: What would be the definition of an array of functions, anyway? Would f[2]() { printf("this if f[0]\n"); } { printf("this is f[1]]\n"); } be one? This isn't legal syntax, nor is there any. An array of pointers to functions (all returning the same type - pointer to char in this example) may be declared char *(*h)[]; -- Ed Gould mt Xinu, 2560 Ninth St., Berkeley, CA 94710 USA {ucbvax,uunet}!mtxinu!ed +1 415 644 0146 "I'll fight them as a woman, not a lady. I'll fight them as an engineer."