tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Variable declaration as first statement in a 'case' b


From: grischka
Subject: Re: [Tinycc-devel] Variable declaration as first statement in a 'case' block gives error.
Date: Wed, 17 Jan 2024 16:15:09 +0100
User-agent: Mozilla/5.0 (Windows NT 6.0; rv:38.0) Gecko/20100101 Thunderbird/38.5.0

On 15.01.2024 00:34, Brad Robinson via Tinycc-devel wrote:
Hey All,

First post here.  Firstly, thank you all for your work on this project.  I 
discovered tcc just a month or so ago and really enjoying using it as a 
back-end code generator for a custom scripting language I'm working on.

Anyway, I noticed this small bug:

A variable declaration as the first statement in a switch case block fails when 
it shouldn't:

         case 1:
             int z = 123;        // This fails with "identifier expected"
             break;

Hi,

well, yes, no.  As a fact, a variable declaration is not a
statement.

There's a pretty easy workaround, just insert an empty statement before.

         case 1:
             ;                   // This fixes it
             int z = 123;
             break;


Yes, label before statement is allowed, also label before empty
statement, just not label before no statement.

As for example "label: }" is not allowed either (in the theory).

See also what gcc has to say:

test.c: In function 'main':
test.c:7:23: error: a label can only be part of a statement and a declaration 
is not a statement
    switch(a) case 1: int z;
                      ^~~

Which of course if a lot better than just "identifier expected"
I would agree that far.

-- gr

(this was build of the mob repo on github - not sure if that affects things).

Brad



reply via email to

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