CJ said:
I think gcc is saying syntax such as "for(int ii=0;ii < 1;ii++) ;" is
not allowed, a statement containing a declaration, "int ii."
As for "Declarations are arguably 'code'" in-so-far registers are
assigned values, I can agree. But CPU registers are not "hidden" from
the c programmer. In assembler, declarations are indeed code, IMHO.
I think you meant to say that CPU registers are hidden from the C
programmer (i.e., you had an extra "not"). But I fail to see what
this has to do with the question of whether declarations are "code".
We're never going to settle this definitively, since there's no formal
definition of the word "code" (at least not in the C standard). But
clearly both declarations and statements can involve the evaluation of
expressions, including function calls, which can result in the
execution of statements. A declaration is executed in much the same
sense that a statement is. (In Ada, for example, the execution of a
declaration is called "elaboration": statements are executed,
declarations are elaborated, and expressions are evaluated.)
Consider:
#include <stdio.h>
int main(void)
{
/* A declaration that performs output: */
int dummy = printf("Hello, world\n");
/* A statement that does nothing: */
;
return 0;
}
I'd call that declaration "code".
It's not a big deal either way, though (<OT>but I'd like to see the
gcc warning "ISO C90 forbids mixed declarations and code" changed to
"ISO C90 forbids mixed declarations and statements"</OT>).