Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!munnari.oz.au!brolga!bunyip.cc.uq.oz.au!lance!ptcburp!michi From: michi@ptcburp.ptcbu.oz.au (Michael Henning) Newsgroups: comp.bugs.4bsd Subject: Re: lint fails to be my friend Message-ID: <380@ptcburp.ptcbu.oz.au> Date: 4 Apr 91 05:30:49 GMT References: <1059@eplunix.UUCP> Organization: Pyramid Technology Corporation Lines: 45 das@eplunix.UUCP (David Steffens) writes: >Try the following on your favorite flavor of lint. The first four if's >generate "variable may be used before set" complains as expected. >The fifth if statement does not. I think it should. If not, why not?? >Tested on 4.2bsd, 4.3bsd, SunOS4.0.3, SunOS4.1 and RTU5.0 (SysV variant). >main() >{ > int foo; > int *bar, *blap, *flap; > int baz[10]; > if (foo == 0) > printf("Yikes!\n"); > if (bar == 0) > printf("Egads!\n"); > if (*blap == 0) > printf("Gadzooks!\n"); > if (flap[2] == 0) > printf("Ack!\n"); > if (baz[2] == 0) > printf("Eh?\n"); > exit(0); >} The reason is that 'baz' is an array, and lint cannot check whether an individual array element has been initialized, since that cannot always be figured out at compile time. The net effect is that you *never* get a warning if you use an array element that is not initialized. In contrast, 'flap' is pointer which is not initialized at the time it is first used, so you *do* get a warning. The fact that you are indexing of the pointer has nothing to do with it, you get the same warning if you replace the fourth test with if (flap == 0) printf("Ack!\n"); Michi. -- -m------- Michael Henning +61 75 950255 ---mmm----- Pyramid Technology +61 75 522475 FAX -----mmmmm--- Research Park, Bond University michi@ptcburp.ptcbu.oz.au -------mmmmmmm- Gold Coast, Q 4229, AUSTRALIA uunet!munnari!ptcburp.oz!michi