tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] C99 for loop with variable declarations


From: Kirill Smelkov
Subject: Re: [Tinycc-devel] C99 for loop with variable declarations
Date: Wed, 23 Jun 2010 21:57:54 +0400
User-agent: Mutt/1.5.6i

On Mon, Jun 21, 2010 at 04:42:37PM +0200, Claudio Bley wrote:
> Hi.
> 
> I just pushed a new change to the mob branch
> (http://repo.or.cz/w/tinycc.git/commit/433ecdfc9d1402ecf03e710de481e2063ad6de90)
>  adding support for C99 for loops a few hours ago.
> 
> A simple test program works as expected:
>     
> --- snip --
> #include <stdio.h>
>     
> int main(int argc, char *argv[]) {
>    int k = 5, i = -1, j = -2;
>    for (int i = 0, j = 9;
>       i < k;
>       ++i, j += i)
>    {
>       printf("%d / %d\n", i, j);
>    }
>    printf("%d / %d\n", i, j);
>    return 0;
> }
> --- snip --
>     
> Output:
>    
> 0 / 9
> 1 / 10
> 2 / 12
> 3 / 15
> 4 / 19
> -1 / -2
>     
> Beware: I merely made some educated guesses as to what some functions
> are doing and just copy'n'pasted a few lines of code. Works for me,
> YMMV.
> 
> Any comments, critics or improvements are welcome.

Maybe also add a test for this into tests/tcctest.c ? And also, let's
maybe add `-std=c99' switch to tcc, because without such an option gcc
complains:

    $ gcc z.c 
    z.c: In function main:
    z.c:5: error: redefinition of i
    z.c:4: note: previous definition of i was here
    z.c:5: error: redefinition of j
    z.c:4: note: previous definition of j was here
    z.c:5: error: for loop initial declarations are only allowed in C99 mode
    z.c:5: note: use option -std=c99 or -std=gnu99 to compile your code

?


I don't know tcc internals, so no suggestion on that part, but otherwise
this looks useful - thanks.

Kirill




reply via email to

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