Quote:
Originally Posted by jmonier
That's actually a case where the comma is not intended to be used. The real use of the comma in C++ is to separate expressions:
x = (y = 3, y + 1)
sets y = 3 and then sets x = (y + 1). Put another way, the comma separated expressions are executed one by one and the value of x is the value of the last expression.
It actually originated in 'C' and is very useful in 'for' statements but I can see how confusing it is when coming from another language that has a totally different use for it. C and C++ are very rich languages and that's why they've been around for so long, but nobody ever said they were easy to understand.
|
A perfect example of a completely useless, counter-intuitive, unexplained and error-prone syntax “feature” that is only useful to code golfers. This is something I'd expect to see in perl, not C++.