Zero-length static array spec

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 6 08:57:11 PST 2015


On Fri, 06 Feb 2015 16:33:49 +0000, David Nadlinger 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).

that's easy: just start assigning increasing addresses from end of ram or 
start of ram for each "infinitely small" local. as passing it's address 
is an invalid operation, the only valid thing one can do is compare it 
with null or some other address, and pass the result of comparison, so 
it's ok.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150206/fde845c0/attachment.sig>


More information about the Digitalmars-d mailing list