Is associated assignment in C / C ++ undefined behavior?

Ignoring variable types, is this expression like a=b=cthat defined behavior in both C and C ++?

If so, can someone give me an official certificate, for example, quotes from the standard?

PS I was looking for a seconded assignment, but all I have is associativity, but I did not find any text about this in the C99 standard. Maybe I did it wrong? hoping someone could help me.

+4
source share
4 answers

From the C ++ standard

5.17 [expr.ass] 1 (=) . lvalue lvalue, . -, . , , .

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

C

6.5.16 3 , . , 111) , lvalue. - lvalue. . .

, . ++ lvalue, , C , 111) , lvalue.

, ++

int a, b = 20;

( a = 10 ) = b;

C .

+6

. a=b=c a=(b=c). (b=c) (b).

+1

C ++, , ,

a=b=c;

:

a=(b=c);

b=c , b . , " " ( ) ++, , - !

+1

. 6.5.16 (3) C99:

, [...]

Together with the right-associative assessment and assuming non-volatile a, band c, this means that it is a = b = cequivalent a = (b = c)and again equivalent b = c; a = b.

0
source

Source: https://habr.com/ru/post/1533154/


All Articles