Signed-unsigned comparisons in Phobos

Timon Gehr timon.gehr at gmx.ch
Fri Aug 12 12:47:19 PDT 2011


On 08/12/2011 09:32 PM, bearophile wrote:
> 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

That is because it is not a comma operator. It is an argument list. ;)
array[(i, j)] = 5;
works fine.


More information about the Digitalmars-d mailing list