From 2402ef005e4f9296ad3313983253f23208a2d7c6 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 6 Sep 2009 16:44:16 +0000 Subject: [PATCH] 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 --- src/cc65/declare.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 */ -- 2.39.5