Bug in usage of associative array: dynamic array with string as a key

Ali Çehreli acehreli at yahoo.com
Fri Jun 30 20:12:08 UTC 2023


On 6/30/23 12:05, Cecil Ward wrote:
 > I have code roughly like the following:
 >
 >     dstring str = "name"d;

Aside: One almost never needs dstring.

 >     uint ordinal =  (( str in Decls.ordinals ) !is null)  ?
 > Decls.ordinals[ str ]  :  -1;
 >
 > struct Decls
 >     {
 >     uint[ dstring]   ordinals;

Do you mean 'ordinals' is 'static'? Otherwise, Decls.ordinals does not 
compile.

 >     }
 >
 > //and
 >     Decls.ordinals[ str ] = ordinal_counter++;

Are you doing that *after* you initialize 'ordinal' as you show here? :)

Ali



More information about the Digitalmars-d-learn mailing list