tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] "identifier expected"? But not by GCC.


From: KHMan
Subject: Re: [Tinycc-devel] "identifier expected"? But not by GCC.
Date: Sat, 18 Apr 2009 12:02:24 +0800
User-agent: Thunderbird 2.0.0.16 (Windows/20080708)

lostgallifreyan wrote:
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.  [snip snip]
[snip]
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.

I tried the following on:
gcc version 3.4.5 (mingw-vista special r3)

$ cat test.c
#include <stdlib.h>
int main()
{
    switch (0) {
        case 1: int a = 10; break;
    }
    return 0;
}

$ gcc -c test.c
test.c: In function `main':
test.c:5: error: syntax error before "int"

Very strange. I've always added braces for such cases where the scope is appropriate and I don't believe gcc 3.4.x and above ever allow such things. (Which was why I explicitly tested it.) Are you compiling in C++ mode? That wouldn't be good practice if there is a commitment to code stuff in a platform-neutral and compiler-neutral way. Other compilers that assumes proper C code may break on such code snippets.

Anyway, this is getting to be OT, so I'll stop here.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia




reply via email to

[Prev in Thread] Current Thread [Next in Thread]