Multiple assignment
bearophile
bearophileHUGS at lycos.com
Fri Feb 25 16:56:56 PST 2011
Is this program showing a bug in multiple assignments (DMD 2.052)?
void main() {
int i;
int[2] x;
i, x[i] = 1;
assert(x == [1, 0]); // OK
int j;
int[2] y;
y[j], j = 1;
assert(y == [0, 0]); // Not OK
}
At the end of the program I expect y to be [1,0] instead of [0,0].
Yet this C program with GCC:
#include "stdio.h"
int main() {
int i = 0;
int x[2] = {0, 0};
i, x[i] = 1;
printf("%d %d\n", x[0], x[1]);
int j = 0;
int y[2] = {0, 0};
y[j], j = 1;
printf("%d %d\n", y[0], y[1]);
return 0;
}
has the same output as DMD:
1 0
0 0
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list