I’m late to the party, but I just discovered that expressions such as x[a++]++ - x[a++]++ were valid Javascript. Is that an UB? If not, how are expressions with side-effects guaranteed to be evaluated?
-
-
Replying to @jedisct1
Calling
@BrendanEich. I've wondered about this, too. I don't know the answer for any language other than C/C++. (I mean, I know it's unknowable for C/C++, a known unknown).1 reply 0 retweets 0 likes -
Replying to @ErrataRob @jedisct1
ECMA-262 specifies much more defined behavior, for interop, and has since 1997. Order of evaluation observable due to metaprogramming hooks in base not meta layer of language, so complete spec required. The spec uses an ad-hoc operational semantics. Generally left-to-right order.
1 reply 0 retweets 1 like -
One entry: https://www.ecma-international.org/ecma-262/9.0/index.html#sec-update-expressions …. To log semantic steps across x[a++]++ - x[a++]++ will take more space than I have, and can trigger userland JS as noted via metaprogramming (getters & setters, valueOf/toString), but is fully specified. No "UB, GCC can break you lol" nonsense.
2 replies 1 retweet 3 likes
Thanks for clarifying!
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.