"chandanlinster" <ch************@gmail.comwrites:
In K&R (page 210, A8), "declaration" is defined to be:
declaration:
declaration-specifiers init-declarators-list(opt);
Later (3rd paragraph), it says that, "empty declarations are not
permitted".
According to the former definition of "declaration" (which specifies
"declarators" as
being optional) "empty declarations" should be permitted.
So i tried out the following program ...
/***************************/
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int;
putchar('\n');
exit(0);
}
/**************************/
... and compiled it using ...
$cc prog.c -ansi -pedantic
prog.c: In function 'main':
prog.c:5: warning: useless type name in empty declaration
So i got only a warning (not an error).
As far as the standard is concerned, there are only diagnostics.
There is not distinction between warnings and errors.
The final question would be:- "Are declarators(or "identifiers")
optional?
I have not checked the standard because it is a curious case where the
compiler wins either way!
(a) If they are allowed (by the standard) then the compiler is still
permitted to issue a diagnostic provided it translates the program
(which it did).
(b) If they are not allowed, the compiler must issue a diagnostic
(which it did) but it *may*, if it so wishes, continue to translate
the program.
You could ask if the standard defines the meaning of:
#include <stdlib.h>
struct s1 { int x; int i; };
struct s2 { int x; int; };
int main(void)
{
return sizeof(struct s1) == sizeof(struct s2) ?
EXIT_SUCCESS : EXIT_FAILURE;
}
but then I'd have to look it up.
--
Ben.