One difference between C and C++ is that C++ allows a label to precede a
declaration, but C doesn't. This is a side effect of the way C and C++
express the ability to mix declarations and statements within a block.
In C, a compound-statement contains a list of block-items, where a
block-item is a declaration or a statement (possibly a
labeled-statement). In C++, a compound-statement contains a list of
statements, but a declaration in a block is syntactically a
declaration-statement.
C23 (as of N3047) permits labels anywhere in a block, including on a
declaration and (unlike C++) just before the closing "}". It redefines
a block-item to be any of a declaration, an unlabeled-statement, or a
label.
{
LABEL1: // Invalid in C17, valid in C23 and C++
int n = 42;
LABEL2: // Valid in C and C++
printf("n = %d\n", n);
LABEL3:; // Valid in C and C++
LABEL3: // Valid in C23, invalid in C17 and C++
}
--
Keith Thompson (The_Other_Keith)
Keith.S.T...@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */