-release compiler switch and associative arrays

Vijay Nayar madric at gmail.com
Tue Oct 11 08:07:03 PDT 2011


On Tue, 11 Oct 2011 14:45:38 +0000, Vijay Nayar wrote:

> On Sun, 09 Oct 2011 12:24:24 +0100, Graham Cole wrote:
> 
>> I understand from the documentation that the "-release" compiler switch
>> turns off "array bounds checking for system and trusted functions".
>> 
>> Is it correct that the following code should seg fault when compiled
>> with "-release" ?
>> 
>> string[string] h;
>> h["abc"] = "def";
>> string s = h["aaa"];
>> 
>> I.e. retrieving from an associative array for a non existent key.
>> 
>> I would have thought that an exception should be generated in this case
>> when compiled with "-release" (as it is when compiled without).
>> 
>> This code behaves the same when compiled by both D1 and D2.
>> 
>> Should I report this as a bug ?

Oh, if your question is specifically about associative arrays, like string
[string], then the reason why there is no out-of-bounds problem is that D 
associative arrays are sparsely populated and support insertion.

http://www.digitalmars.com/d/2.0/arrays.html#associative

 - Vijay


More information about the Digitalmars-d-learn mailing list