On 2010-01-18 00:42, Trass3r wrote:
It is implemented in the runtime so why doesn't it work?


/***********************
* Computes:
* a[] = b[] + c[]
*/

T[] _arraySliceSliceAddSliceAssign_f(T[] a, T[] c, T[] b)
...
...



void main()
{
float[] a = [0.f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f];
float[] b = [0.f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f];

// float[] c = a[] + b[]; // <-- Array operation a[] + b[] not implemented
float[] d = a[] * 4.f + 1.f;
writeln(d); // <-- access violation when program is run
}

This is Bug 3066: http://d.puremagic.com/issues/show_bug.cgi?id=3066

Your code is invalid, since per the spec (http://www.digitalmars.com/d/1.0/arrays.html) array operations are valid only on the RHS of an assignment when there's a slice on the LHS. In your case, you're not performing an assignment at all, you're initializing, and array operations are not valid initializers.

To fix, preallocate and then perform the array op:

auto c = new float[a.length];
c[] = a[] + b[];
auto d = new float[a.length];
d[] = a[] * 4.f + 1.f;

--
E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi

Reply via email to