tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] [PATCH] Parentheses handling within struct/union initiali


From: Marc Andre Tanner
Subject: [Tinycc-devel] [PATCH] Parentheses handling within struct/union initialization
Date: Fri, 28 Sep 2007 18:47:09 +0200
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)

The following can't be compiled, tcc complains: ',' expected.

typedef unsigned char uint8_t ;
typedef unsigned short int uint16_t ;
typedef unsigned int uint32_t ;
typedef struct _IPADDR IPADDR ;
typedef uint32_t in_addr_t ;

struct in6_addr {
        union {
                uint8_t u6_addr8 [ 16 ] ;
                uint16_t u6_addr16 [ 8 ] ;
                uint32_t u6_addr32 [ 4 ] ;
        } in6_u ;
} ;

struct _IPADDR {
        unsigned short family ;
        struct in6_addr ip ;
} ;


IPADDR ip4_any = {
        2,
        { ( ( in_addr_t ) 0x00000000 ) } // broken
//      {  ( in_addr_t ) 0x00000000  }   // this would work
};

Attached is a patch which fixes this particular case i am not 100% sure if it has a negative impact on other constructs, however my tests were successful. With this patch applied and _FILE_OFFSET_BITS != 64 (see my other thread for details) i could successfully compile & run irssi[1].

Note also the comment in the source:

        /* XXX: this test is incorrect for local initializers
           beginning with ( without {. It would be much more difficult
           to do it correctly (ideally, the expression parser should
           be used in all cases) */

i have currently no idea how a solution with the expression parser would look like.

Marc

[1] http://www.irssi.org/
--
 Marc Andre Tanner >< http://www.brain-dump.org/ >< GPG key: CF7D56C0
diff -r a62ad123624a tcc.c
--- a/tcc.c     Sat Sep 22 04:39:52 2007 -0500
+++ b/tcc.c     Fri Sep 21 06:31:33 2007 +0200
@@ -7700,6 +7700,7 @@ static void decl_initializer(CType *type
 {
     int index, array_length, n, no_oblock, nb, parlevel, i;
     int size1, align1, expr_type;
+    static int par_count = 0;
     Sym *s, *f;
     CType *t1;
 
@@ -7791,6 +7792,10 @@ static void decl_initializer(CType *type
                    same time) */
                 if (index >= n && no_oblock)
                     break;
+                while(tok == ')'){
+                    par_count--;
+                    next();
+                }
                 if (tok == '}')
                     break;
                 skip(',');
@@ -7808,7 +7813,6 @@ static void decl_initializer(CType *type
             s->c = array_length;
     } else if ((type->t & VT_BTYPE) == VT_STRUCT &&
                (sec || !first || tok == '{')) {
-        int par_count;
 
         /* NOTE: the previous test is a specific case for automatic
            struct/union init */
@@ -7818,7 +7822,6 @@ static void decl_initializer(CType *type
            beginning with ( without {. It would be much more difficult
            to do it correctly (ideally, the expression parser should
            be used in all cases) */
-        par_count = 0;
         if (tok == '(') {
             AttributeDef ad1;
             CType type1;
@@ -7870,7 +7873,7 @@ static void decl_initializer(CType *type
         }
         if (!no_oblock)
             skip('}');
-        while (par_count) {
+        while (par_count > 0) {
             skip(')');
             par_count--;
         }

reply via email to

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