bug in assigning to dynamic array element

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Sat Nov 1 05:58:26 PDT 2014


On 1 November 2014 12:39, ketmar via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Sat, 1 Nov 2014 12:34:50 +0000
> Iain Buclaw via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>
>> On 1 November 2014 09:03, ketmar via Digitalmars-d
>> <digitalmars-d at puremagic.com> wrote:
>> > Hello.
>> >
>> > let's run this code:
>> >
>> >       info.list[idx] = saveIt(info, count-1); //!!!
>>
>> You could use:
>>
>> emplace(&info.list[idx], saveIt(info, count-1));
> i know some workarounds, i just want to know how can i explain this
> nonsense to newcomers. "please, remember that you can't safely assign
> values to array elements"?

Or how about: Every side effect is evaluated LTR.  So whatever you do,
don't have LHS-altering side-effects on the RHS.  It may be over the
top to explain simply that it is questionable and potentially wrong to
assume that things happen in a given order.  But you may not be too
far off the mark to explain that when the need for an explicit order
is required, do it yourself.  Avoid surprises.


More information about the Digitalmars-d mailing list