Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!agate!pasteur!ames!ncar!tank!uxc!uxc.cso.uiuc.edu!a.cs.uiuc.edu!s.cs.uiuc.edu!carroll From: carroll@s.cs.uiuc.edu Newsgroups: comp.lang.c Subject: Re: array[-1] -- permitted? Message-ID: <207600003@s.cs.uiuc.edu> Date: 23 Sep 88 16:33:00 GMT References: <164701@<1988Sep19> Lines: 24 Nf-ID: #R:<1988Sep19:164701:s.cs.uiuc.edu:207600003:000:1317 Nf-From: s.cs.uiuc.edu!carroll Sep 23 11:33:00 1988 /* Written 1:42 am Sep 22, 1988 by kyriazis@rpics in s.cs.uiuc.edu:comp.lang.c */ Excuse for the question, but that is the first time I am looking at that subject and I don't see any reason why x[-a] can't be permitted (...) Am I missing something? kyriazis@turing.cs.rpi.edu ------------------------------ /* End of text from s.cs.uiuc.edu:comp.lang.c */ The problem arises on machines with non-linear address spaces. The classic example is the 80x86 family from Intel. Address on this machine consist of two parts - the segment and offset. For large arrays, it is handy to have the array start at the beginning of segment, and make the segment large enough to hold the array. Therefore, array arithmetic is done only with the offset, making the code run much faster. Unfortunately, the price you pay is that negative absolute indices 'wrap around' the segment, and give bizarre results. This can be finessed in YACC by declaring the array and a pointer, and then if YACC has a 'largest' negative index of 1 or 2, set pointer = array + 1 or 2, and things work fine. I hope this makes things clearer. Alan M. Carroll carroll@s.cs.uiuc.edu Grad Student / U of Ill - Urbana ...{pur-ee,convex}!uiucdcs!s!carroll "Too many fools who don't think twice, too many ways to pay the price" - AP&EW