Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site bbncca.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!talcott!wjh12!bbncca!keesan From: keesan@bbncca.ARPA (Morris Keesan) Newsgroups: net.lang.c Subject: Re: declaring routines which return function pointers Message-ID: <1224@bbncca.ARPA> Date: Tue, 18-Dec-84 10:32:17 EST Article-I.D.: bbncca.1224 Posted: Tue Dec 18 10:32:17 1984 Date-Received: Thu, 20-Dec-84 00:28:14 EST References: <249@alberta.UUCP> <423@gitpyr.UUCP> <1957@umcp-cs.UUCP> Organization: Bolt, Beranek and Newman, Cambridge, Ma. Lines: 28 ---------------- USE TYPEDEFS!! Sure, you can use "longhand", and declare f as a pointer to function returning int, and declare fa as a function returning a pointer to function returning int, but even if you know what you're doing [ basic rule -- as you pronounce the English from left to right, build the declaration from the innermost parentheses out ] and manage to correctly build the declarations int (*f)(); int (*(fa()))(); /* Yes, I know there's a redundant pair of () */ you've got code which the next person will have to spend five minutes deciphering, even with comments. Compare the above with typedef (*PFI)(); /* Pointer to function returning int */ PFI f, fa(); Why would anyone choose the former? This, to my mind, is the major beauty of typedefs. Information hiding is all well and good, but can be accomplished by judicious use of #defines, without typedefs. Using typedefs allows you to break down complex type declarations into manageable chunks, providing much more readable code, and much less chance of getting the declaration wrong in the first place. -- Morris M. Keesan {decvax,linus,ihnp4,wivax,wjh12,ima}!bbncca!keesan keesan @ BBN-UNIX.ARPA