Don't promote -3 to int either
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 25 Jul 2001 19:53:19 +0000 (19:53 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 25 Jul 2001 19:53:19 +0000 (19:53 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1103 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCval.c

index 51214a5527be2a4db634c3f41a0bb0910261da0d..2f5b9710076e6d14edd5cd26af3363233eb4c067 100644 (file)
@@ -309,31 +309,32 @@ constVal (char *s)
   else
     sval = atol (s);
 
-
+  // check if we have to promote to long
   if (SPEC_LONG (val->type) || 
       (SPEC_USIGN(val->type) && sval>0xffff) ||
-      (!SPEC_USIGN(val->type) && ((long)sval>32767 || (long)sval<-32768)) {
+      (!SPEC_USIGN(val->type) && ((long)sval>32767 || (long)sval<-32768))) {
       if (SPEC_USIGN (val->type))
        SPEC_CVAL (val->type).v_ulong = sval;
       else
        SPEC_CVAL (val->type).v_long = sval;
       SPEC_LONG (val->type) = 1;
+      return val;
     }
+  
+  if (SPEC_USIGN (val->type))
+    SPEC_CVAL (val->type).v_uint = sval;
   else
-    {
-      if (SPEC_USIGN (val->type))
-       SPEC_CVAL (val->type).v_uint = sval;
-      else
-       SPEC_CVAL (val->type).v_int = sval;
-    }
-
-  // check the size and make it a char if possible
-  if (sval < 256)
+    SPEC_CVAL (val->type).v_int = sval;
+  
+  
+  // check if we can make it a char
+  if ((SPEC_USIGN(val->type) && sval < 256) ||
+      (!SPEC_USIGN(val->type) && ((long)sval<127 && (long)sval>-128))) {
     SPEC_NOUN (val->etype) = V_CHAR;
-
+  }
   return val;
-
 }
+
 /*! /fn char hexEscape(char **src)
 
     /param src Pointer to 'x' from start of hex character value