Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!wuarchive!mit-eddie!uw-beaver!sumax!amc-gw!pilchuck!dataio!bright From: bright@Data-IO.COM (Walter Bright) Newsgroups: comp.lang.c Subject: Re: Array bounds checking with C???? Message-ID: <2693@dataio.Data-IO.COM> Date: 7 Sep 90 18:32:33 GMT References: <1589@redsox.bsw.com> <1340@ontek.com> Organization: Data I/O Corporation; Redmond, WA Lines: 17 In comp.lang.c, campbell@redsox.bsw.com (Larry Campbell) writes: | Are there actually any current compilers out there that are so stupid | that they generate substantially different code for the following two | code fragments? | | /* Fragment 1 */ | for (p = array; p < &array[ARRAY_SIZE]; p++) | *p = '\0'; /* changed from *p++ = 0; */ | | /* Fragment 2 */ | for (i = 0; i < ARRAY_SIZE; i++) | array[i] = '\0'; The optimization that converts 2 to 1 is called 'strength reduction' with 'loop induction variable elimination'. It is an advanced capability of global optimizing compilers, and few compilers do it. Zortech C/C++ does this optimization when it is compiling with full optimization.