digitalmars.D - Array-wise assignment on unallocated array
- Andrej Mitrovic (21/21) Jul 27 2010 There's an example in TDPL showing array-wise expressions. I've modified...
- Kagamin (4/5) Jul 27 2010 array operation is not an array assignment, it's an operation on existin...
- Walter Bright (2/31) Jul 27 2010 Yes, it should throw an out of bounds error.
- Andrej Mitrovic (2/34) Jul 27 2010
There's an example in TDPL showing array-wise expressions. I've modified the
code and removed the allocation. This will compile and run without exceptions:
void main() {
auto a = [0.5, -0.5, 1.5, 2];
auto b = [3.5, 5.5, 4.5, -1];
double[] c;
c[] = (a[] + b[]) / 2;
}
I think assignments to unallocated arrays should throw a runtime exception, or
at least give out a compile warning. Compare this to this code which throws a
RangeError:
import std.stdio;
void main() {
double[] c;
c[0] = 4;
}
And the equivalent array-wise assignment which doesn't throw exceptions:
import std.stdio;
void main() {
double[] c;
c[] = 4;
}
Bugzilla-worthy?
Jul 27 2010
Andrej Mitrovic Wrote:I think assignments to unallocated arrays should throw a runtime exception, or at least give out a compile warning.array operation is not an array assignment, it's an operation on existing array. null array is an array of length 0. A warning may help here.
Jul 27 2010
Andrej Mitrovic wrote:
There's an example in TDPL showing array-wise expressions. I've modified the
code and removed the allocation. This will compile and run without exceptions:
void main() {
auto a = [0.5, -0.5, 1.5, 2];
auto b = [3.5, 5.5, 4.5, -1];
double[] c;
c[] = (a[] + b[]) / 2;
}
I think assignments to unallocated arrays should throw a runtime exception, or
at least give out a compile warning. Compare this to this code which throws a
RangeError:
import std.stdio;
void main() {
double[] c;
c[0] = 4;
}
And the equivalent array-wise assignment which doesn't throw exceptions:
import std.stdio;
void main() {
double[] c;
c[] = 4;
}
Bugzilla-worthy?
Yes, it should throw an out of bounds error.
Jul 27 2010
Thanks. Filed in bugzilla http://d.puremagic.com/issues/show_bug.cgi?id=4521 Walter Bright Wrote:Andrej Mitrovic wrote:There's an example in TDPL showing array-wise expressions. I've modified the code and removed the allocation. This will compile and run without exceptions: void main() { auto a = [0.5, -0.5, 1.5, 2]; auto b = [3.5, 5.5, 4.5, -1]; double[] c; c[] = (a[] + b[]) / 2; } I think assignments to unallocated arrays should throw a runtime exception, or at least give out a compile warning. Compare this to this code which throws a RangeError: import std.stdio; void main() { double[] c; c[0] = 4; } And the equivalent array-wise assignment which doesn't throw exceptions: import std.stdio; void main() { double[] c; c[] = 4; } Bugzilla-worthy?Yes, it should throw an out of bounds error.
Jul 27 2010









Kagamin <spam here.lot> 