www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Undocumented AA behavior

reply zwang <nehzgnaw gmail.com> writes:
When a key is used in an lvalue associative array, the same key can be 
safely used by the [] operator of a rvalue associative array without 
throwing an ArrayBoundsError exception at run-time. For example:

<code>
int k=1;
int[int] m;       // m: {}
m[k] = m[k]*m[k]; // m: {1->0}
++m[++k];         // m: {1->0, 2->1}
</code>
Aug 04 2005
parent Burton Radons <burton-radons smocky.com> writes:
zwang wrote:

 When a key is used in an lvalue associative array, the same key can be 
 safely used by the [] operator of a rvalue associative array without 
 throwing an ArrayBoundsError exception at run-time. For example:
 
 <code>
 int k=1;
 int[int] m;       // m: {}
 m[k] = m[k]*m[k]; // m: {1->0}
 ++m[++k];         // m: {1->0, 2->1}
 </code>
That should read "Undefined AA behavior"; a different implementation could throw an ArrayBoundsError on it, and could certainly legally refuse to compile the code at all. But let's not get into yet another discussion of C's undefined expression evaluation order.
Aug 04 2005