Changing the behavior of the comma operator

Marc Schütz" <schuetzm at gmx.net> Marc Schütz" <schuetzm at gmx.net>
Wed Mar 26 04:44:38 PDT 2014


On Tuesday, 25 March 2014 at 19:25:43 UTC, ixid wrote:
>> I think this should not be done. Note that even though code 
>> which is D could reintroduce commas safely, C code will still 
>> exist at that time, and likely need porting to D. The 
>> principle that C code should either do the same thing, or not 
>> compile, would be violated.
>
> What would be an example of C code that would compile in a D
> where the comma operator was used for tuples? Also why is cut 
> and
> pasting C code to D so important? If it's non-trivial surely
> people will just use extern C. If it's trivial they can make the
> minor improvements necessary.

This is valid in both C and C++:

   i, j = 0, 1;

It is equivalent to the following:

   i;
   j = 0;
   1;

There might be more complex examples in C++ however, which allows 
more complex L-value expressions. This is invalid C, but valid 
C++:

   (i, j) = (0, 1);

In C++, it is equivalent to:

   j = 1;


More information about the Digitalmars-d mailing list