Zero-length static array spec

David Nadlinger via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 6 08:33:49 PST 2015


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).

David


More information about the Digitalmars-d mailing list