Re: (PR#9610) autosettler "territory" and danger maps

"Russ Lewis" <webmaster-PT/jo28luVbXZCDllQ/[email protected]> Sun, 19 Dec 2004 10:44:21 -0800
Newsgroups gmane.games.freeciv.ai
Message-ID <[email protected]>
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=9610 >

Why not just define a typedef:
    typedef <someIntType> intPtr;
Then, early in main(), you doublecheck that
    sizeof(void*) == sizeof(intPtr)

You'll get a failure the first time that you try to run on a platform 
where it doesn't work...so you know immediately that you have to fix the 
typedef for that platform.

Of course, if you can do the check at compile time, that would be 
better...can an #if statment make that comparison?

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.
>
>-jason
>
>
>
>  
>