Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ukma!xanth!mcnc!ecsvax!dukeac!bet From: bet@dukeac.UUCP (Bennett Todd) Newsgroups: comp.lang.c Subject: Re: Why does lint complain about this? Message-ID: <1385@dukeac.UUCP> Date: 2 May 89 20:20:41 GMT References: <75688@ti-csl.csc.ti.com> <1773@ubu.warwick.UUCP> <8660@xanth.cs.odu.edu> <1794@ubu.warwick.UUCP> Reply-To: bet@dukeac.UUCP (Bennett Todd) Organization: Radiology, Duke Med. Center, Durham, NC Lines: 34 In article <1794@ubu.warwick.UUCP> geoff@cs.warwick.ac.uk (Geoff Rimmer) writes: >[...] >It was my understanding that confirming ANSI compilers will >automatically cast their arguments, if the function has been correctly >prototyped. >[...] >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. I *think* that gcc with the -Wall option should give warnings for any functions called without a prototype in scope; I always compile with gcc using -Wall. I had a large package, containing zillions of functions organized into multiple libraries. I had the library Makefiles generate the library's foo.h file automatically from a template and a sed script which extracted function prototypes from function declarations; I had "make install" install the proper header file in /usr/local/include; I thought I was safe. I called a function which took float parameters, using integer variables for the arguments. I said to myself (very cleverly) "the compiler will generate the cast for me, since I have the proper prototype in scope". KaBOOM! It didn't work. On single-stepping through I found that where I was passing in 128, the function was receiving some ridiculous humongous number. Chagrined, I put in the cast (Rule #1: ALWAYS say exactly what you mean. ALWAYS.). The problem went away. I don't know whether something bizarre happened in my convoluted generation procedure, or whether I tickled some extremely obscure bug in gcc; frankly I don't care. I consider the lesson clear. If the compiler gets it wrong with an explicit cast, then you've got a fatally broken compiler. If what needs to happen can be sufficiently unclear and implicit that humans and/or computers can get confused, then maybe it's best to avoid it? -Bennett bet@orion.mc.duke.edu