[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]
David Pfitzner <dwpfitzner@xxxxxxxxx> writes:
> Falk Hueffner <falk.hueffner@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> > [1] It seems when using ints as keys, the current code uses the void*
> > of the hash_bucket to point to the int, instead of stuffing the int
> > directly into the void* (which should always be at least as large as
> > an int). Is there a certain reason for this?
>
> 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.
Falk
|
|