I often find C and C++ Standards difficult to read and understand, even the simple English sentences and their wordings give terrible experience. On the top of it, the language grammar is totally hell. I'm sure many share the same feeling, at least my friends do.
I would like to understand it by some examples. Lets begin with this (which tries to explain why the conditional expression in C++
is different from the conditional expression in C
: (quoted from wikipedia)
The binding of operators in C and C++ is specified (in the corresponding Standards) by a factored language grammar, rather than a precedence table. This creates some subtle conflicts. For example, in C, the syntax for a conditional expression is:
logical-OR-expression ? expression : conditional-expression
while in C++ it is:
logical-OR-expression ? expression : assignment-expression
Hence, the expression:
e = a < d ? a++ : a = d
is parsed differently in the two languages. In C, this expression is a syntax error, but many compilers parse it as:
e = ((a < d ? a++ : a) = d)
which is a semantic error, since the result of the conditional-expression (which might be a++) is not an lvalue. In C++, it is parsed as:
e = (a < d ? a++ : (a = d))
which is a valid expression.
Please someone explain the bold text in the above quotation! Please explain the grammar with few more examples (especially those where C and C++ differ).
EDIT : I just want to know how to read and understand them. I mean, if I were to explain that in spoken English, then how would I do that?