negative lengths and reverse pointers

Ameer Armaly ameer_armaly at hotmail.com
Thu Oct 19 13:19:30 PDT 2006


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 
is negative, the pointer points to the end of the memmory chunk as opposed 
to the beginning.  When you assign a negative length, all the compiler would 
have to do is find the endpoint of the positive version of the length you 
gave it and set the pointer to point to that.  This way array.reverse simply 
= array.length * -1, which would allow you to go through an array backwards 
with much more efficiency.  Kind of random, but might be useful; ideas?

-- 


Ameer
---
Life is either tragedy or comedy. Usually it's your choice. You can whine or 
you can laugh.
--Animorphs 





More information about the Digitalmars-d mailing list