Array operations, dynamic arrays and length

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 2 05:59:03 PDT 2015


On 7/2/15 8:21 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm at gmx.net>" wrote:
> On Thursday, 2 July 2015 at 10:48:56 UTC, Steven Schveighoffer wrote:
>> On 7/1/15 8:36 PM, J Miller wrote:
>>
>>> Oh, and to make things really confusing, "auto e = a[] - b[]" and "int[]
>>> e = a[] - b[]" both cause "Error: array operation a[] - b[] without
>>> destination memory not allowed".
>>>
>>> Using dmd 2.067.0.
>>
>> This is not a bug. You need to allocate memory before you can write to
>> it. Automatic allocation doesn't happen in D.
>
> This particular part works as intended, but the other things _are_ buggy.

Right, my point was to address an obvious misconception on how these 
statements work. Other languages happily will allocate a new array in 
such cases, D does not.

-Steve


More information about the Digitalmars-d-learn mailing list