negative lengths and reverse pointers
Larry Evans
cppljevans at cos-internet.com
Sat Oct 21 13:07:05 PDT 2006
On 10/19/2006 03:19 PM, Ameer Armaly wrote:
> Hi all. After thinking about foreach_reverse and arrays, a rather strange
> idea hit me: what if we had reverse arrays, where whenever you tried to
> access an element it would go backwards instead of forwards in a memmory
> block to find it? This could be indicated by a negative length; if length
This sounds like something in Timothy Budd's book:
http://web.engr.oregonstate.edu/~budd/Books/aplc/
In that, he had an "expansion vector" which was just the
partial product of the array sizes. E.g. if the array
sizes were 2,3,4, i.e. like a c array X x[2][3][4],
then the expansion vector would be
1,2,6,24
hea also had an offset or something like that and then
I think it was called direction, which was 1 when
access was in the forward direction, and -1 when it was
in the reverse direction. The offset was 0 when in
the forward direction and 24(last value of expansion vector
above) when in the reverse direction. Then to access the
element i0,i1,i2, just multiply each by corresponding
element in expanstion vector and multiply by the direction.
There was a direction for each dimension and I don't recall
the details. I can get the book from the library if you're
interested and provide more details.
More information about the Digitalmars-d
mailing list