D Logic bug

Jonathan Marler johnnymarler at gmail.com
Fri Oct 12 01:16:39 UTC 2018


On Thursday, 11 October 2018 at 23:29:05 UTC, Steven 
Schveighoffer wrote:
> On 10/11/18 7:17 PM, Jonathan Marler wrote:
>
>> 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.  This is likely a result of the grammar 
>> differences rather than an intention one.  For example, the 
>> "Conditional operator" in D actually has a higher priority 
>> than an assignment, but in C++ it's the same and is evaluated 
>> right-to-left.  So this expression would be different in C++ 
>> and D:
>> 
>
> Not in my C/D code. It would have copious parentheses 
> everywhere :)
>

Good :)

> That case is actually very strange, I don't know if it's 
> something that's really common.
>

Yes, that explains why myself, Jonathan Davis and certainly 
others didn't know there were actually differences between C++ 
and D Operator precedence :)  I wasn't sure myself but having a 
quick look at each's operator precedence table made it easy to 
find an expression that behaves differently in both.



More information about the Digitalmars-d mailing list