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!mhuxr!ihnp4!bbncca!keesan From: keesan@bbncca.ARPA (Morris M. Keesan) Newsgroups: net.lang.c Subject: Re: C type declarations Message-ID: <1268@bbncca.ARPA> Date: Fri, 18-Jan-85 11:14:34 EST Article-I.D.: bbncca.1268 Posted: Fri Jan 18 11:14:34 1985 Date-Received: Sat, 19-Jan-85 01:27:19 EST References: <7262@brl-tgr.ARPA> Organization: Bolt, Beranek and Newman, Cambridge, Ma. Lines: 33 ------------------------------- Indeed, changing the syntax of C type declarations at this point is totally infeasible and would break lots of existing programs. (The previous article suggested parsing type declarations from left to right instead of by precedence.) However, there is another way to greatly simplify C type declarations that was added to the language several years ago, in V7 UNIX(tm). This is the typedef facility, and allows you to break up your declaration into smaller pieces. E.g., instead of int i; /* integer */ int if(); /* integer function */ int *ip; /* Integer Pointer */ int *fpi(); /* Function returning Pointer to Int */ int (*pfi)(); /* Pointer to Function returning Int */ int (*(apfi[15]))(); /* Array of 15 Pointers to Functions returning Int */ and other declarations of increasing complexity, you can say: int i; typedef int Intfunc(); typedef int *Intptr; /* So far, about the same */ typedef Intptr FuncretIntptr(); /* Here is where it starts to get simpler */ typedef Intfunc *PtrtoIntfunc; PtrtoIntfunc apfi[15]; /* Isn't this one much more readable than the above? */ and of course you can choose the names for these types to conform to your own mnemonic ideals. These days, I never write a declaration with more than one sort of type symbol in it (from the set *, (), and []), and I find my declarations are much more readable and consistently bug-free. -- Morris M. Keesan {decvax,linus,ihnp4,wivax,wjh12,ima}!bbncca!keesan keesan @ BBN-UNIX.ARPA