I use coma operator all the time:
int a, b;
for (a=1,b=1;a<3;++a,++b)
...
Probably some other cases.
By specification coma operator allows to call a sequence of instructions where one is allowed.
Sotrue?(++a,b+=2,a+b):(a+=2,++b,a-b)will evaluate ++a,b+=2 and return a+b. The other awesome thing with coma that it breaks rule for necessity of braces for blocks of code. Multiply instruction can be folded into one:
if (a == b)
a=1, cout << a+b;

2 comments:
Last example illustrates strong WTF abilities of C++ language.
Every language has it's own WTF code style =). Perl especially ;)
Post a Comment