Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2001:
[Freeciv-Dev] Re: int -> void*, was Re: [RFC] Attaching information to o
Home

[Freeciv-Dev] Re: int -> void*, was Re: [RFC] Attaching information to o

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: int -> void*, was Re: [RFC] Attaching information to objects
From: David Pfitzner <dwpfitzner@xxxxxxxxx>
Date: Wed, 17 Jan 2001 19:22:25 -0800 (PST)

Falk Hueffner <falk.hueffner@xxxxxxxxxxxxxxxxxxxxxxxx> wrote: 

> David Pfitzner <dwpfitzner@xxxxxxxxx> writes:
 
> > Is it guaranteed by the language that stuffing the int into the
> > void* will always work, or does it just happen to work on most
> > (all?) platforms?
> 
> I don't think this is guaranteed to work. But I really don't know of
> *any* platform where it wouldn't work. While it is pretty common that
> pointers take more bits than ints, the opposite would be very weird.
> 
> > Eg, could you have a platform on which a particular int bit pattern
> > happened to be invalid as a pointer value, and the implementation
> > happened to notice this at runtime and throw up its hands in
> > horror?
> 
> It's not usual for compiled C programs to do such checks...
> 
> BTW, the Athena widget set and gtk make the assumption that this
> works all the time, and there haven't been any problems so far.

Right, its probably safe enough.  

I notice glib does have wrappers GINT_TO_POINTER(),
GPOINTER_TO_INT(), (along with definig gpointer and gint themselves),
which could perhaps be used to work-around obscure platforms
(ie, in general, not for Freeciv, since may not always have glib.) 

So to answer the original question, I may have been responsible for 
some such code, on the basis that I _knew_ allocating would work, 
compared to wasn't so sure about doing it "directly".

-- David

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/



[Prev in Thread] Current Thread [Next in Thread]