Signed-unsigned comparisons in Phobos

Don nospam at nospam.com
Fri Aug 12 14:06:35 PDT 2011


Timon Gehr wrote:
> 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.

No, it was specifically disallowed.

Version D 2.037 Dec 3, 2009
New/Changed Features
     No more comma operators allowed between [ ].


More information about the Digitalmars-d mailing list