Precedences of unary minus and dot operators

Daniel Kozak kozzi11 at gmail.com
Fri Nov 8 04:53:23 PST 2013


On Friday, 8 November 2013 at 12:49:38 UTC, bearophile wrote:
> This is something that has come out of a thread I have opened 
> in D.learn.
>
> In the thread qznc has answered me:
>
>> Operator precedence of "." is higher than unary minus.
>
>
> That's right:
>
>
> double foo(in double x) {
>     assert (x >= 0);
>     return x;
> }
> void main() {
>     assert(-1.foo == -1);
> }
>
>
> Is this a good design of the operator precedences? Is this 
> worth changing/fixing?
>
> Bye,
> bearophile

 From my POV this is good design. When I see:
assert(-1.foo == -1);
Is same for me as:
assert(-foo(1) == -1);



More information about the Digitalmars-d mailing list