Christian Christmann said:
is this code valid according to ANCI C99?
void foo( void )
{
int a = 10;
}; // semicolon allowed here?
int main( void )
{
foo();
return 0;
}
My question is if the semicolon is permitted at the end of a function (see
foo) or does it have to be omitted like for the main function. I was
trying to get some information on that in the standard ISO/IEC 9899:1999
but could not find an appropriate paragraph. Maybe you have more luck.
It is not allowed, regardless if it is immediately after the main
function or not. In a quick search in the standard, I was unable to
find a clear statement about this either. It is implied (I believe) in
the syntax rules summarized in "Annex A (informative) Language Syntax
Summary"
I traced back from "A.2.4 External definitions" (6.9)
translation-unit" to declarators, etc. and did not see anything that
will allow extra semicolons.
(Interestingly the word "semicolon" appears only once in the 554 pages
document + once in the Index)
For a quick check, assuming gcc handles this particular item properly,
compiling the following with "gcc -std=c99 -ansi -Wall -pedantic"
produces the warning "ISO C does not allow extra `;' outside of a
function" 3 times for each extra semicolon on line 3 and twice for
line 13.
#include <stdlib.h>
int i; ;;; /* line 3 */
int main()
{
;;
i = 0 ;;;
;;;;
return EXIT_SUCCESS ;;;;
}
;; /* line 13 */