Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!wuarchive!mit-eddie!uw-beaver!sumax!thebes!polari!6sigma2 From: 6sigma2@polari.UUCP (Brian Matthews) Newsgroups: comp.lang.c Subject: Re: Array bounds checking: what is legal Message-ID: <2461@polari.UUCP> Date: 3 Sep 90 23:16:49 GMT References: <26196@mimsy.umd.edu> <29051@nigel.ee.udel.edu> <26327@mimsy.umd.edu> Organization: Seattle Online Public Unix (206) 328-4944 Lines: 21 In article <26327@mimsy.umd.edu> chris@mimsy.umd.edu (Chris Torek) writes: |Correct. Given `int a[4];', the following holds: | int *p = a; /* legal */ | a[0], a[1], a[2], a[3]; /* all legal */ | p[0], p[1], p[2], p[3]; /* all legal */ | p = &a[4]; /* legal */ | *p; /* illegal (a[4] does not exist) */ | p--; /* legal */ | p = a; /* legal */ | p--; /* illegal */ | p = &a[4]; /* legal */ | p[-4], p[-3], p[-2], p[-1]; /* all legal */ A minor clarification - where Chris says "illegal", read "undefined". Admittedly a minor point, but "illegal" might lead one to believe the compiler won't accept the code in question. "Undefined" means the compiler may or may not accept the code, and if accepted, the resulting machine code may or may not do something "useful", which is actually the case. -- Brian L. Matthews blm@6sceng.UUCP