Zero-length static array spec

David Nadlinger via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 7 17:29:10 PST 2015


On Sunday, 8 February 2015 at 00:51:21 UTC, Iain Buclaw wrote:
>> I don't think that's a viable option. It would lead to 
>> completely
>> unintuitive behavior like the following:
>>
>> ---
>> bool isEqual(T)(T a, T b) { return a == b; }
>>
>> int[0] a0;
>> int[1] a1;
>>
>> assert(a0.ptr != a1.ptr);
>> assert(isEqual(a0.ptr, a1.ptr));
>> ---
>>
>
> You should be able to solve this in the compiler.  For 
> instance, can
> you define an array type to having a non-fixed size?

I just noticed that I managed to make a typo in the example. a1 
should have also been of type int[0].

In any case, the implementation on the different compiler 
backends is not at all what I'm talking about at this point. You 
proposed special comparison semantics, and I highlighted what 
seems to be a deal-breaker to me. All this is on the language 
spec level and has nothing to do with the backend implementation.

David


More information about the Digitalmars-d mailing list