Re: Java language spec question: statements
Wayne <nospam@all.4me.invalid> writes:
Java has several types of statements such as
declaration statements and expression statements.
The classical C block structure was:
{ /* declarations */
/* statements */ }
. A declaration is a kind of agreement with the compiler
about the meaning of an identifier, but it has no specified
run-time effect. A statement usually has a specified
run-time effect that will happen after the effect of any
preceding statement of the block and before the effect
of any following statement of the block.
(A declaration might have an effect at run-time, such as the
allocation of stack memory, but this is not specified and
might not happen in the order of the declarations written.)
Later, C changed to allow declarations everywhere within a
block. This is also allowed by C++. The C grammar reflects
this, by having a block containing ?block items?, where a
?block item? might be a declaration or a statement. So, in
C, today, a declaration is not a statement, but it is a
?block item?.
In C++, however, a ?compound statement? does not contain
?items?, but ?statements?, therefore, declarations had to
become ?statements? in C++, which - in my opinion - does not
reflect their semantics.
Java, then, tried to appear ?similar to C++? and, therefore,
followed C++ in this regard.