Changing the behavior of the comma operator

deadalnix deadalnix at gmail.com
Wed Mar 26 21:35:38 PDT 2014


On Thursday, 27 March 2014 at 02:08:50 UTC, Steven Schveighoffer 
wrote:
> 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

I think you get operator priority wrong and it will be (i), (j = 
0), (1). I added extra () to show how operator priority works.


More information about the Digitalmars-d mailing list