Zero-length static array spec
via Digitalmars-d
digitalmars-d at puremagic.com
Sat Feb 7 12:35:55 PST 2015
On Saturday, 7 February 2015 at 12:10:45 UTC, Iain Buclaw wrote:
> 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)
Why's that? Shouldn't _all_ 0 size variables compare equal? I'd
say that follows from the definition:
array1 == array2
<=>
all corresponding elements of both arrays are equal
<=>
no corresponding elements of both arrays are different
For the last one, it's obvious that this applies to empty arrays:
they don't even contain elements that could compare unequal.
Or maybe you're only talking about the addresses here?
More information about the Digitalmars-d
mailing list