Ist folgendes dokumentiert?
-
Hallo Zusammen!
Wenn ich folgenden Code übersetze kommt (zumindest bei mir) keine Fehlermeldung:
#include <iostream> int main() { int i = 0; i = ("bla", std::cout << "foo" << std::endl, 'b', 'a', 'r', 42); std::cout << "i = " << i << std::endl; return 0; }Wenn ich es dann ausführe kommt als Ausgabe:
foo i = 42Ist dieses Verhalten (d.h. das immer sämtlicher Code in einer solchen folge von Anweisungen ausgeführt wird und der letzte Wert dann zugewiesen wird) irgendwo dokumentiert, hat das einen Namen?
Danke und Grüße,
Maik
-
Nennt sich Kommaopertator:
[quote:ff316626cd="ISO/IEC
14882"]5.18 Comma operator
1 The comma operator groups left-to-right.
expression:
assignment-expression
expression , assignment-expression
A pair of expressions separated by a comma is evaluated left-to-right and the value of the left expression is
discarded. The lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions
are not applied to the left expression. All side effects (1.9) of the left expression, except for the
destruction of temporaries (12.2), are performed before the evaluation of the right expression. The type and
value of the result are the type and value of the right operand; the result is an lvalue if its right operand is.