D Logic bug
Patrick Schluter
Patrick.Schluter at bbox.fr
Fri Oct 12 15:36:40 UTC 2018
On Thursday, 11 October 2018 at 23:17:15 UTC, Jonathan Marler
wrote:
> On Thursday, 11 October 2018 at 21:57:00 UTC, Jonathan M Davis
> wrote:
>> On Thursday, October 11, 2018 1:09:14 PM MDT Jonathan Marler
>> via Digitalmars-d wrote:
>>> On Thursday, 11 October 2018 at 14:35:34 UTC, James Japherson
>>>
>>> wrote:
>>> > [...]
>>>
>>> In c++ the ternary operator is the second most lowest
>>> precedence operator, just above the comma. You can see a
>>> table of each operator and their precendence here, I refer to
>>> it every so often:
>>> https://en.cppreference.com/w/cpp/language/operator_precedence
>>>
>>> Learning that the ternary operator has such a low precedence
>>> is one of those things that all programmers eventually run
>>> into...welcome to the club :)
>>>
>>> It looks like D has a similar table here
>>> (https://wiki.dlang.org/Operator_precedence). However, it
>>> doesn't appear to have the ternary operator in there. On that
>>> note, D would take it's precedence order from C/C++ unless
>>> there's a VERY good reason to change it.
>>
>> The operator precedence matches in D. Because in principle, C
>> code should either be valid D code with the same semantics as
>> it had in C, or it shouldn't compile as D code, changing
>> operator precedence isn't something that D is going to do
>> (though clearly, the ternary operator needs to be added to the
>> table). It would be a disaster for porting code if we did.
>>
>> - Jonathan M Davis
>
> I had a look at the table again, looks like the ternary
> operator is on there, just called the "conditional operator".
> And to clarify, D's operator precedence is close to C/C++ but
> doesn't match exactly.
Please do not conflate C and C++. It is specifically on order of
precedence of the ternary that the 2 languages differ. It is C++
and only C++ which has the unconventionnal order of precedence
where the ternary has the same priority as the assign operators.
ALL other C derived languages have a higher priority for the
ternary than the assignments.
More information about the Digitalmars-d
mailing list