Bug in 4.2BSD C compiler...

David Herron, NPR Lover david at ukma.UUCP
Fri May 10 05:22:18 AEST 1985

In article <1141 at sjuvax.UUCP>, jss at 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 at ANL-MCS.ARPA or ukma!david<@ANL-MCS> 
---	   or david%ukma.uucp at anl-mcs.arpa
---        Or even anlams!ukma!david at ucbvax.arpa
--- UUCP-> {ucbvax,unmvax,boulder,oddjob}!anlams!ukma!david
---        {ihnp4,decvax,ucbvax}!cbosgd!ukma!david

	"It's *Super*User* to the rescue!"

More information about the Comp.lang.c mailing list