Thread overview | |||||
---|---|---|---|---|---|
|
February 06, 2014 void[0][string] hash = [ "text" : [] ] gives empty array. | ||||
---|---|---|---|---|
| ||||
The code compiled and runs successfully: void[0][string] hash = [ "text" : [] ]; writeln(hash); assert(hash.length == 0); Output result is "[]". Is that a bug? |
February 07, 2014 Re: void[0][string] hash = [ "text" : [] ] gives empty array. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cooler | On Thursday, 6 February 2014 at 21:37:34 UTC, Cooler wrote: > The code compiled and runs successfully: > void[0][string] hash = [ "text" : [] ]; > writeln(hash); > assert(hash.length == 0); > > Output result is "[]". > > Is that a bug? http://dlang.org/arrays.html A static array with a dimension of 0 is allowed, but no space is allocated for it. It's useful as the last member of a variable length struct, or as the degenerate case of a template expansion. Judging by compler output, zero size static arrays are removed completely, so no surprise that nothing is done. |
February 07, 2014 Re: void[0][string] hash = [ "text" : [] ] gives empty array. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | On Friday, 7 February 2014 at 03:33:10 UTC, Maxim Fomin wrote:
> On Thursday, 6 February 2014 at 21:37:34 UTC, Cooler wrote:
>> The code compiled and runs successfully:
>> void[0][string] hash = [ "text" : [] ];
>> writeln(hash);
>> assert(hash.length == 0);
>>
>> Output result is "[]".
>>
>> Is that a bug?
>
> http://dlang.org/arrays.html
>
> A static array with a dimension of 0 is allowed, but no space is allocated for it. It's useful as the last member of a variable length struct, or as the degenerate case of a template expansion.
>
> Judging by compler output, zero size static arrays are removed completely, so no surprise that nothing is done.
This should be a compiler error, no?
void[0], OK
void[0][], ERROR
Cheers,
ed
|
Copyright © 1999-2021 by the D Language Foundation