Array bounds checking with C????

Al Dunbar userAKDU at mts.ucs.UAlberta.CA
Sat Sep 8 12:45:37 AEST 1990


In article <1990Sep6.203031.29254 at laguna.ccsf.caltech.edu>, jimmy at tybalt.caltech.edu (Jimmy Hu) writes:
>In article <1589 at redsox.bsw.com> 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';
>>
>>    /* Fragment 2 */
>>    for (i = 0; i < ARRAY_SIZE; i++)
>>       array[i] = '\0';
>>
 
Actually, the first fragment will set every other element of
the array to '?0', as the pointer is incremented twice per trip
through the loop.
-------------------+-------------------------------------------
Al Dunbar          |
Edmonton, Alberta  |   this space for rent
CANADA             |
-------------------+-------------------------------------------



More information about the Comp.lang.c mailing list