The change allows cc65 to be compiled on 64-bit Windows, without getting warnings. That OS is actually 32 bits with 64-bit pointers. Its pointers are "long long" instead of "long". The change uses type-names that are configured for the actual pointer width.
/* common */
#include "check.h"
#include "cpu.h"
+#include "inttypes.h"
#include "strbuf.h"
#include "xmalloc.h"
#include "xsprintf.h"
-static const char* GetLabelName (unsigned Flags, unsigned long Label, long Offs)
+static const char* GetLabelName (unsigned Flags, uintptr_t Label, long Offs)
{
static char Buf [256]; /* Label name */
case CF_ABSOLUTE:
/* Absolute address */
- xsprintf (Buf, sizeof (Buf), "$%04X", (int)((Label+Offs) & 0xFFFF));
+ xsprintf (Buf, sizeof (Buf), "$%04X", (unsigned)((Label+Offs) & 0xFFFF));
break;
case CF_REGVAR:
-void g_getstatic (unsigned flags, unsigned long label, long offs)
+void g_getstatic (unsigned flags, uintptr_t label, long offs)
/* Fetch an static memory cell into the primary register */
{
/* Create the correct label name */
-void g_putstatic (unsigned flags, unsigned long label, long offs)
+void g_putstatic (unsigned flags, uintptr_t label, long offs)
/* Store the primary register into the specified static memory cell */
{
/* Create the correct label name */
-void g_addstatic (unsigned flags, unsigned long label, long offs)
+void g_addstatic (unsigned flags, uintptr_t label, long offs)
/* Add a static variable to ax */
{
unsigned L;
-void g_addeqstatic (unsigned flags, unsigned long label, long offs,
+void g_addeqstatic (unsigned flags, uintptr_t label, long offs,
unsigned long val)
/* Emit += for a static variable */
{
-void g_subeqstatic (unsigned flags, unsigned long label, long offs,
+void g_subeqstatic (unsigned flags, uintptr_t label, long offs,
unsigned long val)
/* Emit -= for a static variable */
{
-void g_addaddr_static (unsigned flags, unsigned long label, long offs)
+void g_addaddr_static (unsigned flags, uintptr_t label, long offs)
/* Add the address of a static variable to ax */
{
/* Create the correct label name */
g_getimmed (CF_STATIC, InitLabel, 0);
AddCodeLine ("jsr pushax");
g_getimmed (CF_INT | CF_UNSIGNED | CF_CONST, Size, 0);
- AddCodeLine ("jsr %s", GetLabelName (CF_EXTERNAL, (unsigned long) "memcpy", 0));
+ AddCodeLine ("jsr %s", GetLabelName (CF_EXTERNAL, (uintptr_t) "memcpy", 0));
}
}
/* common */
#include "coll.h"
+#include "inttypes.h"
/* cc65 */
#include "segments.h"
void g_getimmed (unsigned Flags, unsigned long Val, long Offs);
/* Load a constant into the primary register */
-void g_getstatic (unsigned Flags, unsigned long Label, long Offs);
+void g_getstatic (unsigned Flags, uintptr_t Label, long Offs);
/* Fetch an static memory cell into the primary register */
void g_getlocal (unsigned Flags, int Offs);
-void g_putstatic (unsigned flags, unsigned long label, long offs);
+void g_putstatic (unsigned flags, uintptr_t label, long offs);
/* Store the primary register into the specified static memory cell */
void g_putlocal (unsigned Flags, int Offs, long Val);
void g_addlocal (unsigned flags, int offs);
/* Add a local variable to ax */
-void g_addstatic (unsigned flags, unsigned long label, long offs);
+void g_addstatic (unsigned flags, uintptr_t label, long offs);
/* Add a static variable to ax */
-void g_addeqstatic (unsigned flags, unsigned long label, long offs,
+void g_addeqstatic (unsigned flags, uintptr_t label, long offs,
unsigned long val);
/* Emit += for a static variable */
void g_addeqind (unsigned flags, unsigned offs, unsigned long val);
/* Emit += for the location with address in ax */
-void g_subeqstatic (unsigned flags, unsigned long label, long offs,
+void g_subeqstatic (unsigned flags, uintptr_t label, long offs,
unsigned long val);
/* Emit -= for a static variable */
void g_addaddr_local (unsigned flags, int offs);
/* Add the address of a local variable to ax */
-void g_addaddr_static (unsigned flags, unsigned long label, long offs);
+void g_addaddr_static (unsigned flags, uintptr_t label, long offs);
/* Add the address of a static variable to ax */
/* expr.c
**
** 1998-06-21, Ullrich von Bassewitz
-** 2015-06-26, Greg King
+** 2017-12-05, Greg King
*/
} else if ((Sym->Flags & SC_FUNC) == SC_FUNC) {
/* Function */
E->Flags = E_LOC_GLOBAL | E_RTYPE_LVAL;
- E->Name = (unsigned long) Sym->Name;
+ E->Name = (uintptr_t) Sym->Name;
} else if ((Sym->Flags & SC_AUTO) == SC_AUTO) {
/* Local variable. If this is a parameter for a variadic
** function, we have to add some address calculations, and the
/* Static variable */
if (Sym->Flags & (SC_EXTERN | SC_STORAGE)) {
E->Flags = E_LOC_GLOBAL | E_RTYPE_LVAL;
- E->Name = (unsigned long) Sym->Name;
+ E->Name = (uintptr_t) Sym->Name;
} else {
E->Flags = E_LOC_STATIC | E_RTYPE_LVAL;
E->Name = Sym->V.Label;
Sym = AddGlobalSym (Ident, GetImplicitFuncType(), SC_EXTERN | SC_REF | SC_FUNC);
E->Type = Sym->Type;
E->Flags = E_LOC_GLOBAL | E_RTYPE_RVAL;
- E->Name = (unsigned long) Sym->Name;
+ E->Name = (uintptr_t) Sym->Name;
} else {
/* Undeclared Variable */
Sym = AddLocalSym (Ident, type_int, SC_AUTO | SC_REF, 0);
** Since we don't have a name, invent one.
*/
ED_MakeConstAbs (Expr, 0, GetImplicitFuncType ());
- Expr->Name = (long) IllegalFunc;
+ Expr->Name = (uintptr_t) IllegalFunc;
}
/* Call the function */
FunctionCall (Expr);
#include "exprdesc.h"
#include "stackptr.h"
#include "symentry.h"
-#include "exprdesc.h"
if (Sep != '(') {
fputc (')', F);
}
- fprintf (F, "\nName: 0x%08lX\n", E->Name);
+ fprintf (F, "\nName: 0x%08lX\n", (unsigned long)E->Name);
}
/* common */
#include "fp.h"
#include "inline.h"
+#include "inttypes.h"
/* cc65 */
#include "asmcode.h"
struct SymEntry* Sym; /* Symbol table entry if known */
Type* Type; /* Type array of expression */
unsigned Flags;
- unsigned long Name; /* Name or label number */
+ uintptr_t Name; /* Name pointer or label number */
long IVal; /* Integer value if expression constant */
Double FVal; /* Floating point value */
struct Literal* LVal; /* Literal value */
-/* If we have stdint.h, include it, otherwise try some quesswork on types.
+/* If we have <stdint.h>, include it; otherwise, adapt types from <stddef.h>.
** gcc and msvc don't define __STDC_VERSION__ without special flags, so check
-** for them explicitly. Undefined symbols are replaced by zero, so a check for
-** defined(__GNUC__) or defined(_MSC_VER) is not necessary.
+** for them explicitly. Undefined symbols are replaced by zero; so, checks for
+** defined(__GNUC__) and defined(_MSC_VER) aren't necessary.
*/
#if (__STDC_VERSION__ >= 199901) || (__GNUC__ >= 3) || (_MSC_VER >= 1600)
#include <stdint.h>
#else
-/* Assume long is the largest type available, and assume that pointers can be
-** safely converted into this type and back.
+/* Assume that ptrdiff_t and size_t are wide enough to hold pointers.
+** Assume that they are the widest type.
*/
-typedef long intptr_t;
-typedef unsigned long uintptr_t;
-typedef long intmax_t;
-typedef unsigned long uintmax_t;
-
+#include <stddef.h>
+typedef ptrdiff_t intptr_t;
+typedef size_t uintptr_t;
+typedef ptrdiff_t intmax_t;
+typedef size_t uintmax_t;
#endif
/* End of inttypes.h */
-
#endif