Signed-unsigned comparisons in Phobos

bearophile bearophileHUGS at lycos.com
Fri Aug 12 12:32:00 PDT 2011


Timon Gehr:

> foreach_reverse(i;0..array.length) writeln(array[i]),i--;

I'd like to statically forbid some more usages of the comma operator in D :-)

Some of them are already forbidden compared to C. This is valid C code:

int main() {
    int array[5];
    int i = 1;
    int j = 2;
    array[i, j] = 5;
    return 0;
}

While in D it's forbidden, it catches a possible wrong usage:
Line 5: Error: only one index allowed to index int[5u]

Bye,
bearophile


More information about the Digitalmars-d mailing list