]> git.sur5r.net Git - cc65/commitdiff
Fixed an error: When initializing unions, only the first member can be
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 6 Sep 2009 16:44:16 +0000 (16:44 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 6 Sep 2009 16:44:16 +0000 (16:44 +0000)
initialized.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4121 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/declare.c

index 5d8391e247358c99a652b55a36a77d3dbaf1ae49..47ac9431df68bf6cd1ecd5e421df0d78c9ab3659 100644 (file)
@@ -1833,10 +1833,22 @@ static unsigned ParseStructInit (Type* T, int AllowFlexibleMembers)
          * last struct field).
          */
        Size += ParseInitInternal (Entry->Type, AllowFlexibleMembers && Entry->NextSym == 0);
-       Entry = Entry->NextSym;
-       if (CurTok.Tok != TOK_COMMA)
+
+        /* For unions, only the first member can be initialized */
+        if (IsTypeStruct (T)) {
+            /* Struct */
+            Entry = Entry->NextSym;
+        } else {        
+            /* Union */
+            Entry = 0;
+        }
+
+        /* More initializers? */
+       if (CurTok.Tok == TOK_COMMA) {
+           NextToken ();
+        } else {
            break;
-       NextToken ();
+        }
     }
 
     /* Consume the closing curly brace */