Extra semicolons in C++.
\ Jason Cipriani (24 Jan 2008)
. \ Jason Cipriani (24 Jan 2008)

1 msgMIPS Cross compilation -ffreestanding option
2 msgPowerPC implicit pass-by-reference for structs?
22 msgTiny GCC: Pure, Unadulterated, Object Code
3 msgDebugging Macros
2 msgCortex-M3 Support
1 msgPassing (typedef_name *) args into (typedef_nam...
6 msgIs 'long unsigned long' compliant to standard?
5 msgunrecognized command line option '-c' and '-pipe'
3 msgg77 compiler
1 msgexpr_no_commas
1 msgbuild_modify_expr
8 msgwarning: comparison with string literal results...
5 msgLibrary error message.
1 msgRe: merging with binutils + some bootstrap ques...
1 msgHow to Include kernel macros in a program and c...
1 msgI Love Thee
1 msgalignment/padding when mixing C struct and fort...
2 msgHow can I get help about modifying the gcc code?
2 msgCompatibility between g++ 4.1 and 4.2
Subject:Re: Extra semicolons in C++.
Group:Gcc-help
From:Jason Cipriani
Date:24 Jan 2008


Oh, I think I can answer my own question. I guess it was pretty
stupid, it's been bugging me forever but I guess I just needed to type
it out: Only extra semicolons outside of -functions- are illegal in C
and C++, right? But empty statements themselves are no problem at all
in either language?

Thanks, and sorry about that,
Jason

On Jan 24, 2008 2:26 AM, Jason Cipriani <jason.cipriani> wrote:
> Hello all,
>
> I have been wondering this for a really long time now, since it was
> changed in GCC. In a C source file compiled with -pedantic, an extra
> semicolon would produce the following error, of course:
>
> test.c:9: warning: ISO C does not allow extra `;' outside of a function
>
> I'm assuming this is for the reason it says: because ISO C doesn't
> allow extra semicolons.
>
> What I've always wondered is, why does compiling a C++ file with g++
> -pedantic produce errors about extra semicolons as well?
>
> test.cpp:9: error: extra `;'
>
> I though that extra semicolons were perfectly valid in C++. Is this
> not true? Somebody on another mailing list recently pointed out to me
> (and this is what brought up this question), that the C++ standard
> says:
>
> statement:
> expression-statement
> compound-statement
> ...
>
> expression-statement:
> expression_opt ;
>
> compound-statement:
> { statement-seq_opt }
>
> And the _opt items are optional. So a single semicolon and nothing
> else is a valid "expression statement" and therefore a valid
> "statement". Is something being interpreted wrong here?
>
> Thanks!
> Jason
>
> P.S. Here is the test program:
>
> int main (int argc, char **argv) {
>
> if (0) {
> } else {
> };
>
> return 0;;
>
> };
>


© 2004-2008 readlist.com