Path: utzoo!mnetor!uunet!steinmetz!davidsen From: davidsen@steinmetz.ge.com (William E. Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: Is &a[NTHINGS] legal Message-ID: <10716@steinmetz.ge.com> Date: 4 May 88 17:34:32 GMT References: <12074@tut.cis.ohio-state.edu> Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: General Electric CRD, Schenectady, NY Lines: 33 I don't see that there should be any bounds checking until the pointer or address is dereferenced. Doing a check is of dubious use and will probably break as many valid programs as it helps. Consider: char *x, a[NVAL]; /* if this is legal */ x = &a[0]; /* and this is legal */ x += NVAL; /* then why try to make this illegal? */ x = &a[NVAL]; There are (valid) reasons for wanting to take an address outside the range of an array. Consider an algorithm in which negative subscripts are heavily used (say from Pascal, PL/I, Algol-60, etc). You can do an add each time to normalize the values of the subscript, but it is (a) slower, and (b) hard to read. Therefore: char *x, a[NVAL]; x = &a[NVAL+49]; /* for use with negative subscripts */ x[-50] = 'a'; /* same as a[NVAL] */ If dpANS were going to make C into Pascal, it should have been done by having real enums instead of the botch we have now. The feature appeared (I was told) when cpp ran out of symbol space. It was kept as is to "not break existing programs." -- bill davidsen (wedu@ge-crd.arpa) {uunet | philabs | seismo}!steinmetz!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me