Why does double x = 0,1; not compile?
c++, comma-operator, syntax
Solution
During declarations, the comma in the absence of parenthesis is treated as a separator between declarations. For example:
double x = 0, y = 1;
or
double x = 0, y;
What you typed is the equivalent of
double x = 0;
double 1;
Which is obviously not correct.
Problem
``` double x = 0,1; ``` doesn't compile (tries on on MSVC9.0). The error is ``` C2059 syntax error : 'constant' ``` I do realize that there's a comma there instead of a point, but shouldn't the line above be interpreted as the following? ``` double x = (0,1); //which is double x = 1; ``` Incidentally, the initialization compiles successfully with the parentheses. I was thinking along the lines that `operator ,` has a lower precedence than `operator =`, but in this case `=` is no operator, so this shouldn't be an issue. What syntactic rules determine that ``` double x = 0,1; ``` should be illegal?