Zero-length static array spec

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 6 11:09:52 PST 2015


On 6 February 2015 at 16:33, David Nadlinger via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Sunday, 1 February 2015 at 15:34:48 UTC, Iain Buclaw wrote:
>>
>> Regardless of size, a static array should always have an address on
>> the stack.  Of course, dereferencing said address is undefined.
>>
>> You can also consider it a require that although a zero-length static
>> array may have an address, it doesn't take up any space either.
>>
>> Consider:
>>
>> int[0] data0;
>> int[1] data1;
>>
>>
>> Here, you could expect both data0 and data1 to have the same .ptr
>> address, but data0.ptr == data1.ptr should not succeed either.
>
>
> Let's have a look at a related example:
>
>   int[0] data0;
>   int[0] data1;
>
>   assert(data0.ptr != data1.ptr); // ???
>
> If you want this assert to succeed, how do you ensure that the addresses are
> different without allocating at least one byte of stack space (which
> currently seems to be prohibited by the "does not take up space" clause).
>

For debugging purposes, it must have a position on the stack pointer.
For semantic purposes, comparing it as being equal to another value
must be false.


More information about the Digitalmars-d mailing list