Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!uflorida!ziggy!screamer!tscs!tct!chip From: chip@tct.uucp (Chip Salzenberg) Newsgroups: comp.lang.c Subject: Re: Array bounds checking with C???? Message-ID: <26E524CF.1A3@tct.uucp> Date: 5 Sep 90 16:16:15 GMT References: <1589@redsox.bsw.com> Organization: Teltronics/TCT, Sarasota, FL Lines: 27 Larry Campbell flames compiler writers for generating different code for these fragments: > /* Fragment 1 */ > for (p = array; p < &array[ARRAY_SIZE]; p++) > *p++ = '\0'; > > /* Fragment 2 */ > for (i = 0; i < ARRAY_SIZE; i++) > array[i] = '\0'; Mr. Campbell here makes a good point about compiler optimization. However, Mr. Campbell also writes: >If the answer to my question is "no", then the only excuse for permitting >array indices past the end of an array is for compiling old, crufty code >from clay tablets. Many C programmers use pointers for clarity, not just out of habit. My code, including my brand new code, frequently uses pointer navigation within arrays. This feature is useful, and its use is not confined to "old, crufty code". Other programming languages get along without pointers into arrays. That's one of the reasons I don't use those other languages. -- Chip Salzenberg at Teltronics/TCT ,