[:] as empty associative array literal, plus warning for null

monarch_dodra monarchdodra at gmail.com
Thu Jul 4 08:37:42 PDT 2013


On Thursday, 4 July 2013 at 15:27:17 UTC, Timon Gehr wrote:
> On 07/04/2013 04:35 PM, Andrei Alexandrescu wrote:
>> On 7/4/13 6:32 AM, Steven Schveighoffer wrote:
>>> I would not be opposed to a pull request that made [] be 
>>> non-null, as
>>> long as it doesn't allocate.
>>
>> What would be the benefits?
>>
>> Andrei
>
> - Additional sentinel values at basically no cost.
>
> - No accidental flawed relying on empty array is null or empty 
> array !is null.
>   (i.e. less nondeterminism.)
>
> - One thing less to discuss (this has come up before.)

There are no benefits to making "[]" return null either. 
Implementation wise, instead of returning a void[] with "ptr == 
0x0" and "length == 0", it could just as well return a void[] 
with "ptr == 0x1" and "length == 0".

You'd get better behavior at no extra cost.


More information about the Digitalmars-d mailing list