diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index d0e552ced..e323f20ec 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -598,6 +598,18 @@ type* Indirect (type* T) +type* ArrayToPtr (const type* T) +/* Convert an array to a pointer to it's first element */ +{ + /* Function must only be called for an array */ + CHECK ((T[0] & T_MASK_TYPE) == T_TYPE_ARRAY); + + /* Return pointer to first element */ + return PointerTo (T + DECODE_SIZE + 1); +} + + + int IsClassInt (const type* T) /* Return true if this is an integer type */ { diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index 94ae9ec4a..c5a93dc4d 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -270,6 +270,9 @@ type* Indirect (type* Type); * given type points to. */ +type* ArrayToPtr (const type* Type); +/* Convert an array to a pointer to it's first element */ + #if defined(HAVE_INLINE) INLINE int IsTypeChar (const type* T) /* Return true if this is a character type */ diff --git a/src/cc65/exprdesc.c b/src/cc65/exprdesc.c index f31d4ef6b..b09702538 100644 --- a/src/cc65/exprdesc.c +++ b/src/cc65/exprdesc.c @@ -59,16 +59,18 @@ void MakeConstIntExpr (ExprDesc* Expr, long Value) void PrintExprDesc (FILE* F, ExprDesc* E) /* Print an ExprDesc */ { - fprintf (F, "Symbol: %s\n", E->Sym? E->Sym->Name : "(none)"); - fprintf (F, "Type: "); + fprintf (F, "Symbol: %s\n", E->Sym? E->Sym->Name : "(none)"); if (E->Type) { + fprintf (F, "Type: "); PrintType (F, E->Type); + fprintf (F, "\nRaw type: "); + PrintRawType (F, E->Type); } else { - fprintf (F, "(unknown)"); + fprintf (F, "Type: (unknown)\n" + "Raw type: (unknown)\n"); } - fprintf (F, "\n"); - fprintf (F, "Value: 0x%08lX\n", E->ConstVal); - fprintf (F, "Flags: "); + fprintf (F, "Value: 0x%08lX\n", E->ConstVal); + fprintf (F, "Flags: "); switch (E->Flags & E_MCTYPE) { case E_TCONST: fprintf (F, "E_TCONST "); break; case E_TGLAB: fprintf (F, "E_TGLAB "); break; @@ -94,18 +96,16 @@ void PrintExprDesc (FILE* F, ExprDesc* E) if ((E->Flags & E_MCONST) == E_MCONST) { fprintf (F, "E_MCONST "); } - fprintf (F, "\n"); - fprintf (F, "Test: "); + fprintf (F, "\nTest: "); if (E->Test & E_CC) { fprintf (F, "E_CC "); } if (E->Test & E_FORCETEST) { fprintf (F, "E_FORCETEST "); } - fprintf (F, "\n"); - fprintf (F, "Name: 0x%08lX\n", E->Name); + fprintf (F, "\nName: 0x%08lX\n", E->Name); } diff --git a/src/cc65/typecast.c b/src/cc65/typecast.c index ec9409a12..4984192f4 100644 --- a/src/cc65/typecast.c +++ b/src/cc65/typecast.c @@ -73,11 +73,13 @@ int TypeCast (ExprDesc* lval) /* Read the expression we have to cast */ k = hie10 (lval); - /* If the expression is a function or an array, treat it as - * "pointer to type" + /* If the expression is a function, treat it as pointer to function. + * If the expression is an array, treat it as pointer to first element. */ - if (IsTypeFunc (lval->Type) || IsTypeArray (lval->Type)) { + if (IsTypeFunc (lval->Type)) { lval->Type = PointerTo (lval->Type); + } else if (IsTypeArray (lval->Type)) { + lval->Type = ArrayToPtr (lval->Type); } /* Remember the old type */