Loop optimization (was Re: Array bounds checking with C????)

Anton Rang rang at cs.wisc.edu
Thu Sep 6 14:34:57 AEST 1990


In article <1589 at redsox.bsw.com> campbell at redsox.bsw.com (Larry Campbell) writes:
>    /* Fragment 1 */
>    for (p = array; p < &array[ARRAY_SIZE]; p++)
>	*p++ = '\0';

        ^^^^                                 ^^^
   presumably only one of these increments is wanted...

>    /* Fragment 2 */
>    for (i = 0; i < ARRAY_SIZE; i++)
>	array[i] = '\0';

  The MIPS compiler generates identical code for these (and two
similar cases I checked).  GNU C on an MC68020, which usually
generates better code than any other 68000-series compiler I've seen,
uses array operations for the second loop (at least 1.37.1 does).

>If the answer to my question is "yes", then I think we should flame the
>culpable compiler vendors to a crisp.

  Yep...it's time for compiler authors to stop putting so much of the
burden on programs, IMHO.  (Then again, I like Pascal too... :-)

	Anton
   
+---------------------------+------------------+-------------+
| Anton Rang (grad student) | rang at cs.wisc.edu | UW--Madison |
+---------------------------+------------------+-------------+



More information about the Comp.lang.c mailing list