* src/SDCCval.h: fixed bug #1739860 - sdcc does not work correctly on some
[fw/sdcc] / src / SDCCval.h
index 27950882065d6d31391d0ec78c9920b0d20a5906..bb49bee7eb9bd0da24f715f4200776b006bba6a7 100644 (file)
 
 #include "SDCCsymt.h"
 
+
+/* double to unsigned long conversion */
+/*
+ * See ISO/IEC 9899, chapter 6.3.1.4 Real floating and integer:
+ * If the value of the integral part cannot be represented by the integer type, the behavior is undefined.
+ * This shows up on Mac OS X i386 platform
+ */
+/*
+ * on Mac OS X ppc (long) 2147483648.0 equals to 2147483647, so we explicitely convert it to 0x80000000
+ * on other known platforms (long) 2147483648.0 equals to -2147483648
+ */
+#define double2ul(val)  ((val <= (double)0x80000000UL) ? 0x80000000UL : (((val) < 0) ? (unsigned long) -((long) -(val)) : (unsigned long) (val)))
+
 /* value wrapper */
 typedef struct value
   {
-    char name[SDCC_NAME_MAX + 1];      /* operand accessing this value */
-    sym_link *type;            /* start of type chain     */
-    sym_link *etype;           /* end of type chain       */
-    symbol *sym;               /* Original Symbol         */
-    struct value *next;                /* used in initializer list */
-    unsigned vArgs:1;          /* arg list ended with variable arg           */
+    char name[SDCC_NAME_MAX + 1]; /* operand accessing this value     */
+    sym_link *type;               /* start of type chain              */
+    sym_link *etype;              /* end of type chain                */
+    symbol *sym;                  /* Original Symbol                  */
+    struct value *next;           /* used in initializer list         */
+    unsigned vArgs:1;             /* arg list ended with variable arg */
 
   }
 value;
@@ -61,8 +74,8 @@ typedef struct initList
     char *filename;
     union
       {
-       struct ast *node;
-       struct initList *deep;
+        struct ast *node;
+        struct initList *deep;
       }
     init;
 
@@ -80,21 +93,22 @@ typedef enum
   }
 CCR_RESULT;
 
-#define  IS_VARG(x)            (x->vArgs)
+#define  IS_VARG(x)             (x->vArgs)
 
 /* forward definitions for the symbol table related functions */
 void initValue ();
 value *newValue ();
-value *constVal (char *);
+value *constVal (const char *);
 value *reverseVal (value *);
 value *reverseValWithType (value *);
 value *copyValue (value *);
 value *copyValueChain (value *);
-value *strVal (char *);
-value *charVal (char *);
+value *strVal (const char *);
+value *charVal (const char *);
 value *symbolVal (symbol *);
 void printVal (value *);
 double floatFromVal (value *);
+unsigned long ulFromVal (value *);
 
 /* convert a fixed16x16 type to double */
 double doubleFromFixed16x16(TYPE_TARGET_ULONG value);