Re: GPOINTER_TO_UINT(NULL) == 0 ?



rsteinke w-link net writes:

> From: Jim Edwards <jimedwards altavista com>
> >
> > I think so
> >
> > glibconfig.h:
> > #define GPOINTER_TO_UINT(p) ((guint)  (p))
> > #define GPOINTER_TO_INT(p) ((gint)   (p))
> 
> The thing is, anything in glibconfig.h is _platform specific_.
> On _your platform_, the macros are defined that way,
> so GPOINTER_TO_UINT(NULL) is obviously zero. What I was asking
> was if there were any platforms for which the macro had some weird
> definition that broke this.

I think you can safely assume that GPOINTER_TO_UINT() will be
defined in the most obvious way possible, and on any reasonable
platform this will give you GPOINTER_TO_UINT(NULL) => 0.

(See the C FAQ for information about NULL and unreasonable platforms;
GTK+ basically requires a reasonable platform.)

I suspect that the GTK+ code depends on this assumption in various
places, so I wouldn't worry about making it.

> > but why would you need to make such an assumption?
> 
> I'm storing a ref count as the value in a hash table. Since
> looking up a key in the hash table returns NULL if the key
> isn't found, it's basically impossible to store a NULL
> value. It makes life a lot simpler if that corresponds
> to a ref count of 0, which I don't need to store.

You can use g_hash_table_lookup_extended() to detect NULL values
stored in a hash table. 

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]