Send empty assoc array to function

JN 666total at wp.pl
Thu Jul 9 21:13:49 UTC 2020


On Thursday, 9 July 2020 at 20:24:11 UTC, Steven Schveighoffer 
wrote:
> On 7/9/20 4:04 PM, JN wrote:
>> On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote:
>>> void foo(int[int] bar)
>>> {
>>>     // ...
>>> }
>>>
>>>
>>>
>>> Is it possible to send an empty array literal?
>>>
>>> foo( [ 0 : 2 ] ) works
>>> foo( [] ) doesn't
>>>
>>> int[int] empty;
>>> foo(empty);
>>> works but it's two lines
>> 
>> Hmm, foo(null) seems to work, but is it correct way to do it?
>> 
>
> Yes, that is correct.
>
> -Steve

Interesting. Often in D discussion, an argument pops up that the 
language should be protecting against hidden breakages from API 
changes. This would be an example of that happening.

void foo(int[int] bar), someone calls it with a null, suddenly 
the signature changes to void foo(int* bar) and you will be 
sending a null pointer and possibly breaking the app.


More information about the Digitalmars-d-learn mailing list