Prev: ?k???O?T?h???C
Next: JVM and java application
From: Eric Sosman on 26 Jan 2010 11:28 On 1/25/2010 3:31 PM, Robbo wrote: > [...] > And in (byte)x++, (byte) is first because of higher priority of cast > than postfix ++. > What do you think? Even without checking the JLS, it's easy to see that this is wrong. If the cast had higher precedence, the expression would be equivalent to ( (byte)x )++ .... which is nonsense. Consider a wider context like double x = 42.0; ( (byte)x )++; .... and ponder: "What primitive does the ++ operator modify?" Therefore: If the cast has higher precedence the compiler must reject the expression, so if the compiler accepts it the cast does not have higher precedence. -- Eric Sosman esosman(a)ieee-dot-org.invalid
From: Tom Anderson on 26 Jan 2010 13:17 On Tue, 26 Jan 2010, Thomas Pornin wrote: > According to Lew <noone(a)lewscanon.com>: >> There's no point talking about associativity of prefix ++ if ++++x is an >> illegal expression. > > There is no "associativity" at all for unary operators. Associativity is > a notion which is defined only for binary operators. True. The equivalent for unary operators is probably distributivity, or whatever it's called. Like how -(a+b) == (-a)+(-b). Although of course -(a*b) != (-a)*(-b), so it's a bit more complicated. And not at all related to drawing up tables of operators. tom -- hypnopomp rapist
From: Robbo on 26 Jan 2010 16:39
U�ytkownik "Thomas Pornin" <pornin(a)bolet.org> napisa� w wiadomo�ci news:4b5f0217$0$29839$426a74cc(a)news.free.fr... > According to Lew <noone(a)lewscanon.com>: > > There's no point talking about associativity of prefix ++ if ++++x is an > > illegal expression. > > There is no "associativity" at all for unary operators. Associativity is > a notion which is defined only for binary operators. JLS 3d edition, point 15.15 Unary operators: "The unary operators include +, -, ++, --, ~, !, and cast operators. Expressions with unary operators group right-to-left, so that -~x means the same as -(~x)." |