Array bounds checking with C????
Walter Bright
bright at Data-IO.COM
Sat Sep 8 04:32:33 AEST 1990
In comp.lang.c, campbell at 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.
More information about the Comp.lang.c
mailing list