What's the deal with "Warning: explicit element-wise assignment..."

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 15 01:06:28 PDT 2014


On Tuesday, 15 April 2014 at 06:31:02 UTC, Andrei Alexandrescu 
wrote:
> We've just enabled warnings as errors in our build system at 
> work and suddenly:
>
> Warning: explicit element-wise assignment <exprnew> is better 
> than <expr>
>
> where <exprnew> and <expr> are expressions picked from the 
> code. For example, this wasn't accepted:
>
> writeAvail_[0 .. buf.length] = buf;
>
> but this was:
>
> writeAvail_[0 .. buf.length] = buf[];
>
> The type of the involved variables were as trivial as ubyte[] 
> and in ubyte[] respectively.
>
> What's the idea?
>
>
> Andrei

The correct syntax is

writeAvail_[0 .. buf.length] = buf[];

as the other syntax is for assigning a single value to all 
elements of the destination array. At least that's how I've 
always seen it.

I'm not sure what that warning is talking about though.


More information about the Digitalmars-d mailing list