Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!ptimtc!nntp-server.caltech.edu!manning From: manning@nntp-server.caltech.edu (Evan Marshall Manning) Newsgroups: comp.lang.c Subject: Re: Frequently Asked Array Questions Message-ID: <1991Mar30.182131.2373@nntp-server.caltech.edu> Date: 30 Mar 91 18:21:31 GMT References: <1991Mar15.045933.25690@athena.mit.edu> <1991Mar30.060146.10515@cbnews.att.com> <1991Mar30.081807.21378@athena.mit.edu> Organization: California Institute of Technology, Pasadena Lines: 48 scs@adam.mit.edu (Steve Summit) writes: >> Today, I ran across a situation where a peer had: >> char array[7]; >> if (array == 0) >> No compiler we have complains about it. >> They complain about a test for equality with any other constant >> but 0, but even then, only that it is an illegal pointer/integer >> combination. (I understand that difference). >The conditional expression > if (array == 0) >does not match any of the three exceptions, so the compiler >dutifully generates a pointer to the first element of the array, >and then compares it to the null pointer, which is, as Eric >correctly observes, guaranteed not to succeed. When exposed to >the light of day like this, this behavior does seem odd, but the >compiler is just blindly following the rules, as compilers are >wont to do. >A legitimate message from the compiler in this case would be >"warning: constant in conditional context." (A more interesting >message might be "warning: comparison of constants.") Standard >lint, however, does not make this diagnosis, presumably because >it does not treat array names as the constants they really are. >(In this case, the array name is only quasi-constant, because its >storage class is auto. However, lint doesn't complain about >comparisons of statically-allocated array names, either.) >I've added this case to my lint wish list. PC-Lint from Gimpel (and presumably Flexi-Lint from the same source) Has this to say: _ if (p == 0) temp2.c 6 Warning 506: Constant value Boolean Again, I highly recommend this product. *************************************************************************** Your eyes are weary from staring at the CRT for so | Evan M. Manning long. You feel sleepy. Notice how restful it is | is to watch the cursor blink. Close your eyes. The |manning@gap.cco.caltech.edu opinions stated above are yours. You cannot | manning@mars.jpl.nasa.gov imagine why you ever felt otherwise. | gleeper@tybalt.caltech.edu i=3;do{putchar(((0x18|1<>i%2)^(2<<1+i));}while(i--);