c++ - Is "++l *= m" undefined behaviour? -
i have started studying c++0x. came across follow expression somewhere:
int l = 1, m=2; ++l *= m; i have no idea whether second expression has defined behavior or not. asking here.
isn't ub? eager know.
in code above, prefix ++ has precedence on *=, , gets executed first. result l equals 4.
update: indeed undefined behavior. assumption precedence ruled false.
the reason l both lvalue , rvalue in *=, , in ++. these 2 operations not sequenced. hence l written (and read) twice "without sequence point" (old standard wording), , behavior undefined.
as sidenote, presume question stems changes regarding sequence points in c++0x. c++0x has changed wording regarding "sequence points" "sequenced before", make standard clearer. knowledge, not change behavior of c++.
update 2: turns out there defined sequencing per sections 5.17(1), 5.17(7) , 5.3.2(1) of n3126 draft c++0x. @johannes schaub's answer correct, , documents sequencing of statement. credit should of course go answer.
Comments
Post a Comment