Why does lint complain about this?

Geoff Rimmer geoff at cs.warwick.ac.uk
Sat Apr 29 17:11:36 AEST 1989


In article <8660 at xanth.cs.odu.edu> kremer at cs.odu.edu (Lloyd Kremer) writes:

> In article <1773 at ubu.warwick.UUCP> geoff at cs.warwick.ac.uk (Geoff Rimmer) writes:
> >How did people ever survive without function prototypes! :-)
> 
> They coded correctly, casting function arguments when necessary.
> 
> Prototypes are very helpful in error checking, but it is an unwise practice
> to *depend* on the compiler to do your casting for you.  If a function call
> would need an explicit cast to work correctly in the absence of a prototype,
> then it should have an explicit cast.

It was my understanding that confirming ANSI compilers will
automatically cast their arguments, if the function has been correctly
prototyped.  The only exception would be varadic functions, since a
prototype like

	int execl (char *, char *, ...);

does not tell the compiler what the types of the optional arguments
will be.  This means that your execl example:

> 	   execl(path, arg0, arg1, arg2, (char *)0);

does indeed require a cast even in ANSI C.

However, if I have a function that takes a char pointer, and I have
told the compiler so by means of a prototype, why can't I then call
the function with:

	func(0);    ( or func(NULL); if you prefer)

I'm not sure if you're saying this is wrong, or just bad *style*.
If ANSI compilers are supposed to cast arguments correctly, then I am
perfectly willing to trust my compiler to do so.  If I have omitted a
prototype, I want to be told so by the compiler.  That way I can't
lose (except for varadic as mentioned above) - or can I?

#include <std/cliche'>

> -- 
> 					   Lloyd Kremer
> 					   Brooks Financial Systems
> 					   ...!uunet!xanth!brooks!lloyd

Geoff

	/---------------------------------------------------------------\
	|	GEOFF RIMMER  - Friend of fax booths, ANSI C, PCBH,	|
	|			phone *numbers*	& MPFC & printf		|
	|	email	: geoff at uk.ac.warwick.emerald			|
	|	address : Computer Science Dept, Warwick University, 	|
	|		  Coventry, England.				|
	|	PHONE	: +44 203 692320 (10 lines) If I'm out please	|
	|			   leave a message with my secretary.	|
	|	FAX	: +44 865 726753				|
	\---------------------------------------------------------------/



More information about the Comp.lang.c mailing list