]> git.sur5r.net Git - cc65/blobdiff - src/cc65/locals.c
Fixed a bug
[cc65] / src / cc65 / locals.c
index 4ac8f357a1ad4e4a2ead340df07b068806279d3c..fccc8040e94429ffd5f36384ce1efbcba9f7b146 100644 (file)
@@ -240,20 +240,23 @@ static void ParseOneDecl (const DeclSpec* Spec)
                    /* Skip the '=' */
                    NextToken ();
 
-                   /* Get the expression into the primary */
-                   expression1 (&lval);
-
-                   /* Make type adjustments if needed */
-                   assignadjust (Decl.Type, &lval);
-
                    /* Setup the type flags for the assignment */
-                   flags = TypeOf (Decl.Type);
-                   if (Size == 1) {
-                       flags |= CF_FORCECHAR;
+                   flags = Size == 1? CF_FORCECHAR : CF_NONE;
+
+                   /* Get the expression into the primary */
+                   if (evalexpr (flags, hie1, &lval) == 0) {
+                       /* Constant expression. Adjust the types */
+                       assignadjust (Decl.Type, &lval);
+                       flags |= CF_CONST;
+                       /* Load it into the primary */
+                       exprhs (flags, 0, &lval);
+                   } else {
+                       /* Expression is not constant and in the primary */
+                       assignadjust (Decl.Type, &lval);
                    }
 
                    /* Store the value into the variable */
-                   g_putstatic (flags, SymData, 0);
+                   g_putstatic (flags | TypeOf (Decl.Type), SymData, 0);
 
                    /* Mark the variable as referenced */
                    SC |= SC_REF;