On 08/12/2011 11:06 PM, Don wrote:
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 [ ].

Interesting. So first , inside [ ] was specifically special cased to be a comma operator when indexing into an array (you can overload indexing to take more than one argument) and now those are disallowed? Quite messy. Imho that is just an implementation detail and does not invalidate my statement. (in case you were actually saying that the code should not compile, it does.)

Reply via email to