[freeciv-ai] Re: (PR#9610) autosettler "territory" and danger maps
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=9610 >
On Sun, 19 Dec 2004, Jason Short wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=9610 >
>
> You can't cast an int as a void* and treat it as a pointer. This won't work
> on 64-bit systems
> where sizeof(int) != sizeof(void*). (Or so I'm told; I've never actually
> compiled on a 64-bit
> system.)
>
> There are two choices (unless you want to redesign the movemap to hold unit
> pointers
> directly and work properly with deletions). Probably the better one is to
> malloc(sizeof(int))
> and keep the unit ID in a malloced pointer. Naturally you then have to free
> the pointer
> afterwards. The other is to develop our own version of G_POINTER_TO_INT/
> G_INT_TO_POINTER that could probably just be copied verbatim from the glib
> sources.
> Naturally then we have to make sure this macro works on any new systems that
> turn up in
> the future.
C99 has integer types with sufficient size to hold pointers.
These are intptr_t and uintptr_t (you will need to include <stdint.h>).
On non-C99 systems, I used to hack around this either by using long
(which works most of the time, but not on some weird systems) or
ptrdiff_t. But the C99 way is clearly superior.
Benoit is correct that you shouldn't find a system where sizeof(void *)
is smaller than sizeof(int). Although this is not impossible, all the
architectures I am aware of do not use such schemes.
---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa
- [freeciv-ai] Re: (PR#9610) autosettler "territory" and danger maps,
Vasco Alexandre da Silva Costa <=
|
|