Why does lint complain about this?

Bennett Todd bet at dukeac.UUCP
Wed May 3 06:20:41 AEST 1989


In article <1794 at ubu.warwick.UUCP> geoff at 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 at orion.mc.duke.edu



More information about the Comp.lang.c mailing list