View Single Post
Old 20th October 2011, 23:36   #10306  |  Link
nand chan
( ≖‿≖)
 
Join Date: Jul 2011
Location: BW, Germany
Posts: 380
Quote:
Originally Posted by jmonier View Post
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++.
__________________
Forget about my old .3dlut stuff, just use mpv if you want accurate color management
nand chan is offline   Reply With Quote