[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] "identifier expected"? But not by GCC.
From: |
lostgallifreyan |
Subject: |
Re: [Tinycc-devel] "identifier expected"? But not by GCC. |
Date: |
Fri, 17 Apr 2009 21:10:18 +0100 |
Dave Dodge <address@hidden> wrote:
(17/04/2009 20:41)
>On Sat, Apr 18, 2009 at 03:23:31AM +0800, KHMan wrote:
>> test.c:10: error: a label can only be part of a statement
>> and a declaration is not a statement
>>
>> IIRC it's not ISO C90 compliant. Nothing wrong with tcc. I'll leave the
>> digging up the ISO C standard to others.
>
>According to the C grammar, a declaration is not a statement, but both
>are block items. The reason you can mix them in other contexts is
>because a braced block contains block items rather than just
>statements:
>
> compound-statement:
> '{' block-item-list-opt '}'
>
> block-item:
> declaration
> statement
>
>A labeled statement is more strict and requires a statement rather
>than a block item:
>
> labeled-statement:
> identifier ':' statement
> 'case' constant-expr ':' statement
> 'default' ':' statement
>
Thankyou both. Looks like I missed the bracing when I extracted something from
a case statement in the original. As it looks like using bracing can result in
looser rules, and possible bad practise if unchecked, which do you recommend,
minimising braces and declaring stuff earlier where it works, or using braces
to allow declarations in immediate context?
KHMan, the GCC I tested it with reports itself as "GCC.EXE (GCC) 3.4.5
(mingw-vista special r3)". It's supplied with wxDev-C++. If it hadn't accepted
my code I'd have just carried on looking for my error, but when compilers
disagree it leaves me wondering if I should let them duke it out between
themselves. :) Seriously, as it appears it's a basic C error in hindsight, it's
a very misleading event when it's not flagged by GCC at all, and the complied
program runs as expected too. I initially tried GCC purely to see if its error
reporting gave me further clues, so I hadn't expected that.