lint: shouldn't it catch this?
J.T. Conklin
jtc at van-bc.wimsey.bc.ca
Thu Jan 3 06:49:19 AEST 1991
In article <Jan.2.12.52.08.1991.467 at paul.rutgers.edu> birnbaum at paul.rutgers.edu (Rich Birnbaum) writes:
>Running lint on this program produces no errors:
>
>main()
>{
> int i;
> if (0)
> i=0;
> printf ("%d",i);
>}
>
>Shouldn't it complain that 'i' may be used before set? I could have sworn it
>did at some point in my life!
It should, it doesn't, and ou've probably seen the 'i' may be used
before set mesage before. Rather than doing data flow analysis, lint
raises this warning only if the first use of a variable is access
rather than assignment.
I then tried FlexeLint by Gimpel Software. FlexeLint is a commercial
lint which I highly recommend --- I was _sure_ that it would catch the
bug. I was sadly disappointed. I looked in the manual and the
description for warning 530 explained that it too uses the "first
seen" algorithm. I'm going to write a letter to gimpel urging them to
do better, as this is the first blemish I've discovered in an
otherwise excelent product.
Still, FlexeLint is a bit more thourough that most other lints, so I
thought I'd include a comparison of output.
lint:
test.c
==============
(4) warning: constant in conditional context
(7) warning: main() returns random value to invocation environment
==============
function returns value which is always ignored
printf
flexelint:
FlexeLint (U32) Ver. 4.00F, Copyright Gimpel Software 1985-1990
--- Module: test.c
_
if (0)
test.c 4 Warning 506: Constant value Boolean
_
printf ("%d",i);
test.c 6 Info 718: printf undeclared, assumed to return int
test.c 6 Info 746: call to printf not made in the presence of a prototype
_
}
test.c 7 Warning 533: Return mode of main inconsistent with line 1
--- Global Wrap-up
Warning 526: printf (line 6, file test.c) not defined
Warning 628: no argument information provided for function printf (line 6,
file test.c)
Having a good lint always helps, but like seatbelts, even those of us
with the best intentions forget to use them. Having a compiler with
good diagnostics is a big plus too. Just for kicks, let's see what
gcc gives us:
gcc -O -Wall:
test.c: In function main:
test.c:2: warning: return-type defaults to `int'
test.c:6: warning: implicit declaration of function `printf'
test.c:3: warning: `i' may be used uninitialized in this function
test.c:7: warning: control reaches end of non-void function
Pretty good :-)
--jtc
--
J.T. Conklin Toolsmith, Language Lawyer
...!{uunet,ubc-cs}!van-bc!jtc, jtc at wimsey.bc.ca
More information about the Comp.unix.questions
mailing list