Zero-length static array spec
Iain Buclaw via Digitalmars-d
digitalmars-d at puremagic.com
Sat Feb 7 04:10:36 PST 2015
On 6 February 2015 at 23:42, David Nadlinger via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Friday, 6 February 2015 at 23:37:30 UTC, Iain Buclaw wrote:
>>
>> Simple, you implement it by allocating no memory. :)
>
>
> Let me put it a different way. Imagine you have this in your program:
>
> ---
> void foo() {
> int[0] a0;
> int[0] a1;
> ...
> int[0] a99;
>
> // Do something with them.
> }
> ---
>
> How do you choose the addresses for a0 through a99 so that they are
> distinct, but you don't end up allocating 100 bytes of stack memory?
>
> David
There are no addresses for them, you can't do *anything* with them at runtime.
Some cod scenarios:
1. Comparisons of == fold into 'false' (unless comparing to self)
2. Comparisons of != fold into 'true' (unless comparing to self)
3. Conversion to dynamic arrays is { .length=0, .ptr=&arr0 }
You cannot assign memory/address to them directly, but you can assign
it indirectly. This 'indirect assignment' can only really work if it
were the last member of a struct. Example usage -
http://goo.gl/uAbxKN - something like a pointer-based dynamic array.
Labels probably do best describe their exact behaviour.
Iain.
More information about the Digitalmars-d
mailing list