Bug in usage of associative array: dynamic array with string as a key
Cecil Ward
cecil at cecilward.com
Fri Jun 30 20:14:23 UTC 2023
On Friday, 30 June 2023 at 20:12:08 UTC, Ali Çehreli wrote:
> 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
Hi Ali, ‘ordinal’ is a static initialised explicitly with zero.
More information about the Digitalmars-d-learn
mailing list