more pointer issues
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 27 Sep 2001 10:09:03 +0000 (10:09 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 27 Sep 2001 10:09:03 +0000 (10:09 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1315 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/lib/gbz80/printf.c
device/lib/vprintf.c
device/lib/z80/printf.c
src/SDCCicode.c

index d584bdb8c201db7d8eb643f75ab261d1120b237c..2379d8ad34652f7f2473476dc96b2894de4e031f 100644 (file)
@@ -22,7 +22,7 @@ STATIC void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(ch
     (*emitter)(_hex[u%base], pData);
 }
 
-STATIC void _printf(const char *format, void (*emitter)(char, void *), void *pData, va_list va)
+STATIC void _printf(char *format, void (*emitter)(char, void *), void *pData, va_list va)
 {
     while (*format) {
        if (*format == '%') {
index 77bd361fab7df3a33580a8701466cb6fe8496f36..bbff51b360b542f19a97aac5e80bf39ec712e281 100644 (file)
 #define NULL_STRING_LENGTH 6
 #endif
 
-/* XSPEC is defined in stdio.h and used here to place
-   auto variables in XSEG */
-
 /****************************************************************************/
 
-typedef char * ptr_t;
+//typedef char * ptr_t;
+#define ptr_t char *
 
 #ifdef toupper
 #undef toupper
@@ -256,7 +254,7 @@ static void output_float (float f, unsigned char reqWidth,
 
 /*--------------------------------------------------------------------------*/
 
-int vsprintf (const char *buf, const char *format, va_list ap)
+int vsprintf (const char *buf, char *format, va_list ap)
 {
   static bit            left_justify;
   static bit            zero_padding;
index d584bdb8c201db7d8eb643f75ab261d1120b237c..2379d8ad34652f7f2473476dc96b2894de4e031f 100644 (file)
@@ -22,7 +22,7 @@ STATIC void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(ch
     (*emitter)(_hex[u%base], pData);
 }
 
-STATIC void _printf(const char *format, void (*emitter)(char, void *), void *pData, va_list va)
+STATIC void _printf(char *format, void (*emitter)(char, void *), void *pData, va_list va)
 {
     while (*format) {
        if (*format == '%') {
index 628a1dba9c3664040a13ccbf0c22066d14d00c39..0c512bbf8aee8eb104f1e0e2d87c81f110fe1465 100644 (file)
@@ -1578,6 +1578,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
   sym_link *optype;
   sym_link *opetype = getSpec (optype = operandType (op));
   sym_link *restype;
+  int errors=0;
 
   /* one of them has size zero then error */
   if (IS_VOID (optype))
@@ -1595,10 +1596,9 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
     return operandFromValue (valCastLiteral (type,
                                             operandLitValue (op)));
 
-
   /* if casting to/from pointers, do some checking */
   if (IS_PTR(type)) { // to a pointer
-    if (!IS_PTR(optype)) { // from a non pointer
+    if (!IS_PTR(optype) && !IS_FUNC(optype)) { // from a non pointer
       if (IS_INTEGRAL(optype)) { 
        // maybe this is NULL, than it's ok.
        if (!(IS_LITERAL(optype) && (SPEC_CVAL(optype).v_ulong ==0))) {
@@ -1606,20 +1606,29 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
            // no way to set the storage
            if (IS_LITERAL(optype)) {
              werror(E_LITERAL_GENERIC);
+             errors++;
            } else {
              werror(E_NONPTR2_GENPTR);
+             errors++;
            }
          } else if (implicit) {
            werror(W_INTEGRAL2PTR_NOCAST);
+           errors++;
          }
        }
-      }        else { // shouldn't do that with float, array or structure
-       werror(E_INCOMPAT_TYPES);
+      }        else { 
+       // shouldn't do that with float, array or structure unless to void
+       if (!IS_VOID(getSpec(type)) && 
+           !(IS_CODEPTR(type) && IS_FUNC(optype))) {
+         werror(E_INCOMPAT_TYPES);
+         errors++;
+       }
       }
     } else { // from a pointer to a pointer
       if (implicit) { // if not to generic, they have to match 
        if ((!IS_GENPTR(type) && (DCL_TYPE(optype) != DCL_TYPE(type)))) {
          werror(E_INCOMPAT_PTYPES);
+         errors++;
        }
       }
     }
@@ -1628,12 +1637,23 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
       if (implicit) { // sneaky
        if (IS_INTEGRAL(type)) {
          werror(W_PTR2INTEGRAL_NOCAST);
+         errors++;
        } else { // shouldn't do that with float, array or structure
          werror(E_INCOMPAT_TYPES);
+         errors++;
        }
       }
     }
   }
+  if (errors) {
+    /* fprintf (stderr, "%s%s %d: ", op->operand.symOperand->name,
+       implicit?"(implicit)":"", errors); */
+    fprintf (stderr, "from type '");
+    printTypeChain (optype, stderr);
+    fprintf (stderr, "' to type '");
+    printTypeChain (type, stderr);
+    fprintf (stderr, "'\n");
+  }
 
   /* if they are the same size create an assignment */
   if (getSize (type) == getSize (optype) &&