Disallowing ?:?: syntax

bearophile bearophileHUGS at lycos.com
Mon Jan 5 00:41:48 PST 2009


Where the operation isn't no symmetric, all binary operators (but assignment) in C are left-associative.
But x?y:z is right-associative, so:

x ? y : a ? b : c

is:

x ? y : (a ? b : c)

My little proposal for D is to turn the following into a syntax error, to avoid possile programmer mistakes (so the programmer must put parentheses here to make it compile):

x ? y : a ? b : c

If it becomes a syntax error, then it's better if the error message tells to put how to fix generic code, for example:

"x ? y : a ? b : c  ==> x ? y : (a ? b : c)"

Bye,
bearophile



More information about the Digitalmars-d mailing list