Is chained assignment in C/C++ undefined behavior? -


ignoring types of variables, expression a=b=c has defined behavior in both c , c++?

if so, can 1 give me official evidence, quotes standard, please?

p.s. searched chained assignment got associativity, didn't find text in c99 standard. maybe did wrong? hoping can me.

from c++ standard

5.17 assignment , compound assignment operators [expr.ass] 1 assignment operator (=) , compound assignment operators group right-to-left. require modifiable lvalue left operand , return lvalue referring left operand. result in cases bit-field if left operand bit-field. in cases, assignment sequenced after value computation of right , left operands, , before value computation of assignment expression.

and example there

int a, b; = b = { 1 }; // meaning a=b=1; 

from c standard

6.5.16 assignment operators semantics 3 assignment operator stores value in object designated left operand. assignment expression has value of left operand after assignment,111) but not lvalue. type of assignment expression type left operand have after lvalue conversion. side effect of updating stored value of left operand sequenced after value computations of left , right operands. evaluations of operands unsequenced.

as see there difference. in c++ assignment operator returns an lvalue referring left operand while in c returns value of left operand after assignment,111) but not lvalue.

it means in c++ following code valid

int a, b = 20;  ( = 10 ) = b; 

while in c compiler shall issue error.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -