LINT

Ray Butterworth rbutterworth at watmath.UUCP
Wed May 7 00:26:16 AEST 1986


  > From rbj at icst-cmr (Root Boy Jim) Fri May  2 17:28:02 1986
  > Yes, but it all depends on what you're willing to put up with. I find it
  > terribly ugly having to cast printf's or close's to void.
Not only is it ugly, it's wrong.  Didn't you read in the man page where
it says that these functions return ERROR STATUSES?  Do you believe that
nothing will ever go wrong?  What if programs such as cat(1) didn't check
these error statuses, think what a mess the world would be in.  I mean
if one ran cat from a tape and an I/O error occured, it would probably
just treat it as end-of-file and not tell you that the rest of the
file couldn't be read, and if your file-quota was exhaused cat wouldn't
notice that it couldn't flush its buffers properly and there you would
be with an empty file and cat telling you that everything ran fine.

  > From: woody at juliet.caltech.edu (William E. Woody)
  > Here here!  Though (whenever possible) I try to run my code through lint,
  > I think I only use about a fifth of what lint complains (screams, shouts,
  > moans, groans) about.
I too used to think that most of what lint complained about was crap.
I also noticed an awful lot of things that it didn't complain about but
should have.  So I took the source and turned on all the options that
normally make it shut up about certain things, and then added even more
checks than lint ever had before.  Then I looked at all the crap in the
output and gradually taught lint which one's really were crap and
shouldn't be issued.  Now I have a version of lint with which I use
four fifths of what it complains about.
For instance,
    int i;
    long l;
    short s;
    char *a,*b;
    i=l; s=i;                 /* these both generate warnings */
    i=(int)l; s=(short)i;     /* NO warnings */
    l=i<<100;                 /* warning */
    open("file",0);           /* warning */
    (void)open("file",0);     /* (optional) warning */
    strcpy(a,b);              /* NO warning */
If you assign something that is larger to something that is
smaller lint warns you, but if you explicitly cast it to indicate
that you know it isn't a mistake you get no warning.
There is also an /*OPTRESULT*/ directive which is used like the
/*VARARGS*/ directive in the function definition.  strcpy() is
so defined, and so lint doesn't care whether you look at its
result or not.  But open() is not defined with this directive,
so lint does expect you to look at its return value.  With things
set up this way, it is almost always an error to cast any function
to (void), so lint warns about this too (only as an optional
summary, once per function, not per call).

Too many times I've seen people try to make code lint cleanly
by simply casting all the ignored function returns to (void)
and by using lots of options to tell lint not to complain about
certain things.  Lint really can be useful.  I don't know why
the people who support it don't try to improve it.



More information about the Comp.lang.c mailing list