Komma-Operator
-
Wo wird eigentlich der Komma-Operator überall eingesetzt? Man findet diesen so selten. Ich kenne ihn nur aus for-Schleifen.
-
das komma ist doch eingentlich kein operator, es wird doch nur zum trennen von funktionsparametern benutzt
-
das komma ist doch eingentlich kein operator, es wird doch nur zum trennen von funktionsparametern benutzt
Ich denke schon, dass es in C++ einen Komma-Operator gibt.
http://www.kuzbass.ru:8086/docs/isocpp/expr.html5.18 - Comma operator [expr.comma]
-1- The comma operator groups left-to-right.
expression:
assignment-expression
expression , assignment-expressionA 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 (conv.lval), array-to-pointer (conv.array), and function-to-pointer (conv.func) standard conversions are not applied to the left expression. All side effects (intro.execution) of the left expression, except for the destruction of temporaries (class.temporary), 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.
-2- In contexts where comma is given a special meaning, [Example: in lists of arguments to functions (expr.call) and lists of initializers (dcl.init) ] the comma operator as described in clause expr can appear only in parentheses. [Example:
f(a, (t=3, t+2), c);
has three arguments, the second of which has the value 5. ]
Komma-Operator: http://www.math.uni-wuppertal.de/~axel/skripte/oop/oop4_1.html#oop4_10
/*Man kann mehrere Ausdrücke zu einem zusammenfassen, indem man sie durch Kommas getrennt hintereinander schreibt. Sie werden dann von links nach rechts ausgewertet, und der gesamte Ausdruck hat den Wert des letzten Ausdrucks. Die Werte der anderen Ausdrücke werden nicht verwendet, sie sind nur sinnvoll, wenn sie Seiteneffekte haben. Sinn macht diese Konstruktion vor allem in Schleifen (siehe dazu später). Beispielsweise können so mehrere Variablen in einer for-Schleife initialisiert, bzw. verändert werden:*/ int i; char *P; for ( i=0,P=start ; i<MAX ; ++i,++P ) ... /*Außerdem können Aktionen, die die Auswertung der Schleifenbedingung erst ermöglichen, in die Bedingung eingebaut werden:*/ while ( cin >> c , c!=',' ) cout << c;
-
[edit] Mensch bin ich lagsam [/edit]
ISO/IEC 14882:1998 schrieb:
5.18 Comma operator
1 The comma operator groups left-to-right.
expression:
assignment-expression
expression, assignment-expressionA pair of expressions seperated 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 vonversions 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.
2 In contexts where comma is given a special meaning, [Example: in lists of arguments to functions (5.2.2) and lists of initializers (8.5)] the comma operatoras described in clause 5 can appear only in parantheses.
[Example:f(a, (t = 3, t + 2 ), c );
has three arguments, the second of which has the value 5. ]
Greetz, Swordfish