Merrill & Michele said:
Lawrence said:
Interestingly this is an example (and the only one) of when a compound
statement ISN'T a statement. Check the grammar.
[snip]
I believe Mr. Kirby refers to a statement such as:
i = 6; ++j;
and calls this a compound statement. I can speculate on how many statements
it is and know that I could get it right if I got two swings at the pitch.
I will drag this forum wildly OT if I start into English grammar and its
inability to express truth about number, so which is it? MPJ
(Malformed attribution lines for Lawrence Kirby and Alex Fraser fixed.
"Merrill & Michele", whatever you're doing that creates this problem,
*please* stop doing it. I've noticed that some of your posts have
this problem and some don't. If there are actually two different
people posting from your account, the one who gets this right should
educate the other one.)
No, he's not referring to "i = 6; ++j;". That's not a compound
statement, it's just two statements on one line. It should be clear
from the context that he's referring to the compound-statement from
the '{' to the '}' inclusive.
In most contexts in C source, an end-of-line is just like any other
whitespace. (String literals and macro definitions are the major
exceptions.) There's no grammatical significance to the fact that
both statements are on one line.
If you look at the C grammar, a "compound-statement" consists of a
'{' delimiter, followed by a sequence of zero or more declarations or
statements, followed by a '}' delimiter. (In C90, declarations must
precede statements; in C99, they can be mixed.) The line "i = 6; ++j;"
is not a compound statement because it's not surrounded by '{' and '}'
delimiters.
In general, a compound-statement can appear wherever a statement can
appear. In addition, a compound-statement appears as part of a
function-definition; in that context, according to the grammar, the
compound-statement is not a statement.
The grammar for a function-definition is:
function-definition:
declaration-specifiers declarator declaration-list(opt) compound-statement
(the optional declaration-list is for an old-style non-prototyped
definition). This is the only place in the grammar that allows
(actually requires) a compound-statement without allowing any other
kind of statement.