Changing the behavior of the comma operator

Steven Schveighoffer schveiguy at yahoo.com
Wed Mar 26 19:08:50 PDT 2014


On Wed, 26 Mar 2014 17:32:00 -0400, Nick Sabalausky  
<SeeWebsiteToContactMe at semitwist.com> wrote:

> On 3/26/2014 7:44 AM, "Marc Schütz" <schuetzm at gmx.net>" wrote:
>> This is valid in both C and C++:
>>
>>    i, j = 0, 1;
>>
>> It is equivalent to the following:
>>
>>    i;
>>    j = 0;
>>    1;
>>
>
> Under the proposal, the "0, 1" would be void, so it wouldn't compile in  
> D. Therefore, the rule about moving C code to D safely is not violated.
>

This part of the subthread is about the future plans to possibly use comma  
operators to mean tuples. This C/C++ code will still be valid then, and  
when someone ports to D, might get a nasty silently compiling surprise.

But, I think the proposal to re-introduce ',' as a tuple operator would  
not affect this code, it would remain a 3-element tuple, with i, j, 1 as  
elements (after setting j to 0 of course). '=' has precedence over ','.

The second statement would be a problem (i, j) = (0, 1), but clearly, this  
would not be a valid use case. I can envision there may be some valid use  
cases of that form, however.

-Steve


More information about the Digitalmars-d mailing list