Path: utzoo!utgpu!water!watmath!clyde!burl!codas!mtune!rutgers!rochester!crowl From: crowl@cs.rochester.edu (Lawrence Crowl) Newsgroups: comp.lang.c Subject: Re: Another way (How not to write a loop) Message-ID: <6848@sol.ARPA> Date: 16 Feb 88 16:17:59 GMT References: <560@naucse.UUCP> <1988Feb11.200149.25172@sq.uucp> <2115@bsu-cs.UUCP> <16941@watmath.waterloo.edu> Reply-To: crowl@cs.rochester.edu (Lawrence Crowl) Organization: U of Rochester, CS Dept, Rochester, NY Lines: 28 In article <16941@watmath.waterloo.edu> rbutterworth@watmath.waterloo.edu (Ray Butterworth) writes: ]I just got hit by yet another way not to write a loop: ] ] auto size_t index; ] ] index = sizeof(array) / sizeof(array[0]); ] ] while (--index >= 0) ] blah blah blah ] ]This looks wonderfully portable and works fine on the BSD 4.3 compiler ](and probably most others). ] ]But on an ANSI compiler, (size_t) will be an unsigned integer ]and the loop will go forever. ] ]Lint will notice this problem, but only with the ANSI compiler ]when it is probably too late. Fortunately, there is an easy fix. while ( index-- > 0 ) -- Lawrence Crowl 716-275-9499 University of Rochester crowl@cs.rochester.edu Computer Science Department ...!{allegra,decvax,rutgers}!rochester!crowl Rochester, New York, 14627