Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!mcvax!ukc!warwick!geoff From: geoff@cs.warwick.ac.uk (Geoff Rimmer) Newsgroups: comp.lang.c Subject: Re: Why does lint complain about this? Message-ID: <1794@ubu.warwick.UUCP> Date: 29 Apr 89 07:11:36 GMT References: <75688@ti-csl.csc.ti.com> <1773@ubu.warwick.UUCP> <8660@xanth.cs.odu.edu> Sender: news@warwick.UUCP Organization: Computer Science, Warwick University, UK Lines: 57 In-reply-to: kremer@cs.odu.edu's message of 27 Apr 89 15:12:24 GMT In article <8660@xanth.cs.odu.edu> kremer@cs.odu.edu (Lloyd Kremer) writes: > In article <1773@ubu.warwick.UUCP> geoff@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 > -- > 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@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 | \---------------------------------------------------------------/