Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: Array bounds checking with C???? Message-ID: <1990Aug26.023658.12231@zoo.toronto.edu> Organization: U of Toronto Zoology References: <7611@ucdavis.ucdavis.edu> <26196@mimsy.umd.edu> <619.26d6cfb2@iccgcc.decnet.ab.com> Date: Sun, 26 Aug 90 02:36:58 GMT In article <619.26d6cfb2@iccgcc.decnet.ab.com> browns@iccgcc.decnet.ab.com (Stan Brown, Oak Road Systems) writes: >int arr[4]; > >sizeof arr/sizeof *arr is 4, so &arr[4] may not be legal. Whether legal or >not, the address is certainly outside the array. It is, however, legal, by special dispensation of ANSI C. You can't dereference it, but it is required to behave properly and participate properly in comparisons and arithmetic. Note, this only applies to the address "one after" the end of the array -- both "two after" the end and "one before" the beginning of the array take you into the twilight zone of undefined behavior. -- Committees do harm merely by existing. | Henry Spencer at U of Toronto Zoology -Freeman Dyson | henry@zoo.toronto.edu utzoo!henry