Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cwjcc!gatech!ncsuvx!mcnc!rti!xyzzy!agarn!throopw From: throopw@agarn.dg.com (Wayne A. Throop) Newsgroups: comp.lang.c Subject: Re: Contiguous Arrays Summary: The potential problem is with more than segmented address spaces Message-ID: <3669@xyzzy.UUCP> Date: 27 Feb 89 20:00:49 GMT References: <2508@ssc-vax.UUCP> <8943@alice.UUCP> <1828@valhalla.ee.rochester.edu> <1989Feb22.171441.7957@utzoo.uucp> <1831@valhalla.ee.rochester.edu> <1989Feb23.165715.9013@utzoo.uucp> Sender: usenet@xyzzy.UUCP Lines: 35 > henry@utzoo.uucp (Henry Spencer) > [... avoid calculating addresses that fall outside an array because ...] > It is not true that all machines have a > single linear homogenous address space. Some have it broken up into > pieces, and bad things can happen if your pointer arithmetic goes over > the edge of a piece. Several people have stated the problem as if it were absent on architectures with linear homogenous address spaces. This is not the case. Even linear homogenous address spaces can have over (and under) flow problems for address calculations occuring on arrays allocated "near" the beginning or ending of the whole address space. The example given was adjusting the zero-point of an array like so: int space[10], *x=(space-101); so that x[101] through x[110] would refer to allocated chunks of memory, without wasting the space for elements 0-100. In other words, a poor person's (int [101:110]) type. My point is this. Assumng for whatever reason that one has a large, homogenous, linear address space, and pointer arithmetic checks for overflow and underflow... AND the "space" array is allocated within 100 integer-sized words from the beginning of the address space. Naturally, the calculation that initializes x will fail. And most important to note: LOOK MA: NO SEGMENTATION! ( It seems to me that Henry and Chris and other gurus are aware of this fact. I just thought it ought to be pointed out more strongly that segmentation isn't at fault here. ) (For once.) -- "Here, look him up. Oh yeah, it's under soh-creits." --- Bill and Ted's Excellent Adventure Wayne Throop !mcnc!rti!xyzzy!throopw