Re: [gtk-list] gtk_object_set_data() and integers
- From: Havoc Pennington <hp redhat com>
- To: Gtk-List <gtk-list redhat com>
- Subject: Re: [gtk-list] gtk_object_set_data() and integers
- Date: Fri, 30 Jul 1999 13:46:56 -0700 (PDT)
On Fri, 30 Jul 1999, Michael Vance wrote:
> A simple question: how safe is storing int values in objects using
> gtk_object_set_data(). I've been told many times that assuming that
> sizeof(pointer) >= sizeof(int) can be a very bad decision, and I'm inclined to
> agree. If so, are there any plans for facilities to take care of this issue? Is
> it possible to have a user data structure defined which is simply the union of
> the basic integral types and their pointers and have this be the new unit of
> data storage in Gtk+?
>
There are GINT_TO_POINTER() and GPOINTER_TO_INT() macros in glib. In
practice putting an int in a pointer is pretty safe; but the reverse is
not. The glib macros are intended only to store ints in pointers, not
pointers in ints. (Even if on some weird machine the int is bigger than
the pointer, at worst you lose the top significant bits, so if you're sure
a 32-bit int is big enough you have no problem. If you need 64 bits, you
need to be using gint64 anyway and checking the HAVE_GINT64 macro.)
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]