Subject: Re: ignoring return values from functions.
To: Greg A. Woods <woods@weird.com>
From: Andrew Brown <atatat@atatdot.net>
List: tech-userlevel
Date: 09/20/2001 14:08:51
>>     sleep used( ioctl.c(98) ), but not defined
>>     wait used( ioctl.c(68) ), but not defined
>>     tcsetattr used( ioctl.c(138) ), but not defined
>>     err used( ioctl.c(69) ), but not defined
>>     tcgetattr used( ioctl.c(85) ), but not defined
>
>For these particular errors you'll almost certainly get similar warnings
>from GCC with:
>
>    -Werror -Wall -Wshadow -Wswitch -Wreturn-type -Wpointer-arith -Wconversion -Wimplicit -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
>
>If your code can pass through GCC with the above options enabled then
>it'll generally pass through 'lint' cleanly too (though not always --
>lint does catch things GCC doesn't or cannot).

i just added your warnings en masse to my warnings flags and now i get
this:

   % cc -O2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-uninitialized -Wreturn-type -Wcast-qual -Wpointer-arith -Wwrite-strings -Wswitch -Wshadow -Werror -Werror -Wall -Wshadow -Wswitch -Wreturn-type -Wpointer-arith -Wconversion -Wimplicit -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -c ioctl.c
   % cc -O2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-uninitialized -Wreturn-type -Wcast-qual -Wpointer-arith -Wwrite-strings -Wswitch -Wshadow -Werror -Werror -Wall -Wshadow -Wswitch -Wreturn-type -Wpointer-arith -Wconversion -Wimplicit -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes  -o ioctl ioctl.o -lutil
   % 

so gcc has no problems with that.  lint still doesn't like it.  this
is another problem.  who's right?  are there things i should fix to
make the warnings go away, should i just ignore them, or should i just
tell lint to shut up?  a tool that won't shut up about meaningless
things becomes, itself, meaningless.

>> i can do without.
>
>your decision, obviously -- but don't ever ask me to work on your code
>until after you de-lint it!  ;-)

:P

>Before 'void' the "Indian Hill C Style An Coding Standards a ammended
>for U of T Zoology" (that's the Bell Labs guide, as ammended by Henry
>Spencer) states:
>
>    It is difficult to eliminate complaints about functions whose return
>    value is not used (in the current version of C, at least), but most
>    other messages from 'lint' really do indicate something wrong.
>
>however in the modern land of 'void' (i.e. ANSI/ISO C), even that first
>excuse is gone.  All messages from 'lint' really do indicate something
>is wrong, even if only conceptually and not in practice.

note that in this case, i'm casting things that i'm ignoring to void
(sleep(), printf(), wait(), and sigemptyset()), all prototypes are in
place, etc.

>>  the fact that lint complains than then exits with 0
>> also seems a little suspect to me.
>
>Why?  There's no fault in its finding nits in your code.  It would
>hopefully exit non-zero if it couldn't read the source file or some such
>real error.

i expected it to have a non-zero exit status if it found something to
complain about.

>You'd be surprised what bugs you might find, or even unintentionally
>fix, unrelated to the lint warnings, in a de-linting excercise.

this delinting exercise constisted solely of casting a few functions
to void.  there were no other bugs.

>> >not to preach to the converted or anything, but perhaps this is an
>> >appropriate time to repeat some sage advice:
>> >
>> >           The Ten Commandments for C Programmers
>> >
>> >                       Henry Spencer
>> >
>> >1    Thou shalt run lint frequently and study its pronounce-
>> >     ments with care, for verily its perception  and  judge-
>> >     ment oft exceed thine.
>> 
>> this is one of those things that was written as humor.
>
>you wish....  I know Henry personally (and in fact knew him before that
>was written).  I know for certain that it was written entirely for VERY
>serious purposes and only after he and his colleagues learned all the
>lessons therein the hard way.  I too learned all the same lessons, the
>same hard way, at somewhat the same time too.  That there is humour in
>the way it is written is only to get people who would otherwise ignore
>it to read it and hopefully learn something from it regardless.  You may
>ignore it at your peril, or you may use it to learn those lessons the
>"easy" way.

then his manner and terminology are wrong.  i, for one, would never
have taken that to be anything but pedantic humor because of the way
it was written.

>> having to say ARGSUSED for a function like:
>> 
>>     static void
>>     sigchld(int nsig)
>>     {
>>         if (wait(NULL) == -1)
>>             err(1, "wait");
>>     }
>> 
>> strikes me as practically useless.  having to say NOTREACHED after
>> exit() also seems silly.
>
>obviously you've yet to learn some of the lessons of how to write robust
>code that can be more easily maintained by someone else.

well...it's either ARGSUSED or i cast the function name before using
it like this:

        (void) sigemptyset(&sa.sa_mask);
        sa.sa_handler = (sig_t) sigchld;

ARGSUSED is, in this case and my opinion, the lesser of two obscure
evils.

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
andrew@crossbar.com       * "information is power -- share the wealth."