From: uz Date: Sun, 6 Sep 2009 16:44:16 +0000 (+0000) Subject: Fixed an error: When initializing unions, only the first member can be X-Git-Tag: V2.13.0rc1~135 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2402ef005e4f9296ad3313983253f23208a2d7c6;p=cc65 Fixed an error: When initializing unions, only the first member can be initialized. git-svn-id: svn://svn.cc65.org/cc65/trunk@4121 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 5d8391e24..47ac9431d 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -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 */