Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwvax!rang From: rang@cs.wisc.edu (Anton Rang) Newsgroups: comp.lang.c Subject: Loop optimization (was Re: Array bounds checking with C????) Message-ID: Date: 6 Sep 90 04:34:57 GMT References: <7611@ucdavis.ucdavis.edu> <26196@mimsy.umd.edu> <988@christopher-robin.cs.bham.ac.uk> <1589@redsox.bsw.com> Sender: news@spool.cs.wisc.edu Organization: UW-Madison CS department Lines: 28 In-reply-to: campbell@redsox.bsw.com's message of 4 Sep 90 02:33:10 GMT In article <1589@redsox.bsw.com> campbell@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@cs.wisc.edu | UW--Madison | +---------------------------+------------------+-------------+