Contiguous Arrays
Wayne A. Throop
throopw at agarn.dg.com
Tue Feb 28 06:00:49 AEST 1989
> henry at 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 <the-known-world>!mcnc!rti!xyzzy!throopw
More information about the Comp.lang.c
mailing list