Subject: Re: C vs. prototypes (was: Problems with gdb under NetBSD 1.0 )
To: <>
From: der Mouse <>
List: current-users
Date: 12/16/1994 17:51:23
> K&R C is still the most portable form of C except for cases where
> people change standard functions (i.e. does signal return void or int
> {int is supposed to be the previous signal handler for the signal in
> question so that you can restore it if you wish}, does lseek take a
> long or a quad {note that the 'l' stands for long}).

signal has never returned either void or int; it has always returned
the previous handler.  Whether the _handler_ returns void or int is the
great change in question:

	int (*signal())(); /* old */
	void (*signal(int, void (*)()))(); /* new */

The other great problem with signal, IMO, is that nobody can agree with
anybody else on the argument pattern to the handler (ie, what goes in
the two ()s in the "new" declaration above).

>> Lint did all of the work prototypes attempt to do, but did a far
>> more complete and accurate job of it, and doesn't make/allow
>> mistakes.

(No, instead it produces reams of meaningless messages you can't shut
off and have to wade through to find the _real_ message or two.)

> Yep, ANSI C compilers don't do cross-file checks

At least one does, if you know how to ask it.  I use gcc -Werror -W
-Wall -Wpointer-arith -Wcast-qual -Wwrite-strings -Wstrict-prototypes
-Wmissing-prototypes, and I get cross-file checks because all routines
visible across files must have prototypes in scope everywhere they
appear.  I find this invocation of gcc to be better than lint; it
doesn't produce reams of warnings I have to ignore and produces some
warnings I have never gotten from any lint I've ever seen.

>> Actually, I'd live with prototypes *iff* the automatic type coercion
>> was not available....

gcc -Wconversion is exactly what you want here, I believe:

	  Warn if a prototype causes a type  conversion  that  is
	  different  from  what would happen to the same argument
	  in the absence of a prototype.  [...]

Not that I wish to sound like a gcc apologist; I don't like FSF stuff
in general.  But in my opinion gcc is the one case where the complete
lack of anything anywhere nearly as good outweighs the disadvantages.

					der Mouse