Dik T. Winter said:
Depends on which way you wish to go in the grammar. A compound-statement
is a specific form of a statement (and has been so since the introduction
of the term in Algol 60). So, by all means, the function body is a
statement of particular form (and that was not the case in Algol 60).
In my opinion when Lawrence wrote that that particular compound-statement
was not a statement, he was wrong.
First, let me say that it's really not a very important question; it's
a trivial issue of interest mostly to annoying pedants like me (and
non-annoying pedants like the rest of you who haven't stopped reading
yet).
Let's look at a simple function definition:
int foo(void)
{
return 42;
}
and see how it's parsed.
The whole thing is a function-definition, which expands to:
declaration-specifiers declarator declaration-list(opt) compound-statement
The sub-parts correspond to "int", "foo(void)", (nothing), and
"{ return 42; }", respectively. (I'm not quite certain about the
first three, but the compound-statement is what we're concerned with
here.)
A compound-statement expands to:
{ block-item-list(opt) }
where a block-item-list is a sequence of one or more declarations or
statements (this is in C99; C90 is a bit different here). Obviously
the '{' and '}' match the '{' and '}' delimiters. The block-item-list
matches the sequence consisting of the single statement "return 42;".
At no point in the parsing process is "{ return 42; }" parsed as a
"statement", even though that same token sequence could be a
"statement" if it appeared in a different context.
Similarly, the token sequence "42;" could be a statement (specifically
an expression-statement) if it appeared in a different context, but it
isn't one here.
Q.E.D. (Quite Easily Done)