Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!uw-beaver!tektronix!teklds!copper!stevesu From: stevesu@copper.UUCP Newsgroups: comp.lang.c Subject: Re: help with declaration Message-ID: <1143@copper.TEK.COM> Date: Fri, 19-Jun-87 01:33:08 EDT Article-I.D.: copper.1143 Posted: Fri Jun 19 01:33:08 1987 Date-Received: Sat, 20-Jun-87 07:34:56 EDT References: <8286@ut-sally.UUCP> Organization: Tektronix Inc., Beaverton, Or. Lines: 43 Keywords: function pointer In article <8286@ut-sally.UUCP>, atc@ut-sally.UUCP (Alvin T. Campbell III) writes: > I have a question for all you C wizards out there. I want to write > a function which returns a pointer to another function. Ahh, this brings back fond memories of the first article I ever posted to the net, which asked a related question (couched for some odd reason in King James English). The best way to declare a function returning a pointer to a function returning an int is to use a typedef: typedef int (*PFI)(); PFI function(); This has several advantages: it's much easier to understand, it makes it much easier to figure out which set of parentheses the function's arguments go in (this was my problem three years ago), and if you like to keep the name of the function at the left margin, you don't end up with unbalanced parentheses on the previous line. Compare PFI getroutine(name, table) {...} with int (* getroutine())(name, table) which pcc won't even compile, because the arguments actually belong in the other set of parentheses. Steve Summit stevesu@copper.tek.com