When is the comma operator useful?

The following is probably not very useful as you don’t write it yourself, but a minifier can shrink code using the comma operator. For example: if(x){foo();return bar()}else{return 1} would become: return x?(foo(),bar()):1 The ? : operator can be used now, since the comma operator (to a certain extent) allows for two statements to be written … Read more

Uses of C comma operator [duplicate]

C language (as well as C++) is historically a mix of two completely different programming styles, which one can refer to as “statement programming” and “expression programming”. As you know, every procedural programming language normally supports such fundamental constructs as sequencing and branching (see Structured Programming). These fundamental constructs are present in C/C++ languages in … Read more

How does the Comma Operator work

Take care to notice that the comma operator may be overloaded in C++. The actual behaviour may thus be very different from the one expected. As an example, Boost.Spirit uses the comma operator quite cleverly to implement list initializers for symbol tables. Thus, it makes the following syntax possible and meaningful: keywords = “and”, “or”, … Read more