that is bug?

Patrick Schluter Patrick.Schluter at bbox.fr
Sat Apr 7 16:52:00 UTC 2018


On Saturday, 7 April 2018 at 14:28:05 UTC, kdevel wrote:
> On Saturday, 7 April 2018 at 09:56:43 UTC, Jonathan M Davis 
> wrote:
>>>          true?stt="AA":stt="BB";    <<<<-----///Out:BB
>
> [...]
>
>> Assignment takes precendence over the ternary operator.
>
> That's not true. Not in D and not in C/C++

The odd man out is C++ [1], assignment has higher precedence 
because of right to left evaluation. Do not mix it with C please. 
All other C derived languages have indeed higher precedence for 
ternary than assignment: C [2], java [3], C# [4] and D [5].

[1]: http://en.cppreference.com/w/cpp/language/operator_precedence
[2]: http://en.cppreference.com/w/c/language/operator_precedence
[3]: https://introcs.cs.princeton.edu/java/11precedence/
[4]: 
https://www.tutorialspoint.com/csharp/csharp_operators_precedence.htm
[5]: https://wiki.dlang.org/Operator_precedence

> https://wiki.dlang.org/Operator_precedence
> http://en.cppreference.com/w/c/language/operator_precedence#cite_note-2
>
>> So, no, I don't think that it is. Putting parens around the 
>> assignment expressions makes it print AA.
>
> It should not matter if there are parens around the assignment.
>
>> As it stands, it evaluates both assignment expressions before 
>> evaluating the ternary operator.
>
> That is not true in C/C++, let me quote from a C standard 
> (draft), § 6.1.5 conditional operator:

Stop mixing C with C++ they are really 2 very different beasts 
(one is a programming language, the other is Cthulu :-)

<snip>


More information about the Digitalmars-d mailing list