Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 alpha 4/3/85; site ukma.UUCP Path: utzoo!watmath!clyde!cbosgd!ukma!david From: david@ukma.UUCP (David Herron, NPR Lover) Newsgroups: net.unix,net.bugs.4bsd,net.lang.c Subject: Re: Bug in 4.2BSD C compiler... Message-ID: <1740@ukma.UUCP> Date: Thu, 9-May-85 15:22:18 EDT Article-I.D.: ukma.1740 Posted: Thu May 9 15:22:18 1985 Date-Received: Fri, 10-May-85 06:31:11 EDT References: <1141@sjuvax.UUCP> Distribution: net Organization: U of Kentucky, Mathematical Sciences, Lexington KY Lines: 53 Xref: watmath net.unix:4467 net.bugs.4bsd:1509 net.lang.c:5180 In article <1141@sjuvax.UUCP>, jss@sjuvax.UUCP (J. Shapiro) writes: > Now, several people observed that > > int (*procs[])() = ... > > will work, and this is correct. The question arises on the basis of K&R > pp 114-115, which would seem to indicate that my declaration is acceptable > on the grounds that pointers to integers and pointers to functions returning > integers are supposed to be equationally indistinguishable. You should turn the page to #116. Look at the declaration for sort() which I'll go ahead and quote: sort(v, n, comp, exch) char *v[]; int n; int (*comp)(), (*exch)(); { ... } And they say to pay specific attention to the () around *comp. What is happening is they (K&R) are playing a little loose with the rules. Sure, at the call, the compiler hasn't yet seen the declaration, so the parameters all default to ints. But that doesn't work for all compilers on all systems. The best thing to do is to declare everything PROPERLY, do all the casts your supposed to, etc. Then you get caught by silly things like compilers which don't have void, and don't allow typedefs to void. > > Would someone be good enough to try this on System V and tell me if the silly > thing typed correctly compiles? I tried it on System Vr2 on a 3B2. It don't work. Like it shouldn't > I don't want to make this a religious battle - I will use what works, but it > did strike me as curious that three of the four C compilers I use regularly > take this without complaint, and that the loser was 4.2BSD. Is this version > right or wrong? This version is most correct. Run your code through lint. It'll complain about too many things, but it'll give you something to look think about. -- --- David Herron --- ARPA-> ukma!david@ANL-MCS.ARPA or ukma!david<@ANL-MCS> --- or david%ukma.uucp@anl-mcs.arpa --- Or even anlams!ukma!david@ucbvax.arpa --- UUCP-> {ucbvax,unmvax,boulder,oddjob}!anlams!ukma!david --- {ihnp4,decvax,ucbvax}!cbosgd!ukma!david "It's *Super*User* to the rescue!"