Re: [gtk-list] Re: How to use a gpointer?



On Fri, 5 Mar 1999, Ulric Eriksson wrote:

> 
> On Thu, 4 Mar 1999, Tim Janik wrote:
> 
> > On Thu, 4 Mar 1999, Ulric Eriksson wrote:
> > 
> > > Well spank me with a wet noodle if I'm wrong, but here is cut-and-paste
> > > from glib.h of 1.2:
> > > 
> > > 8<--------
> > > typedef int    gint;
> > > ...
> > > typedef void* gpointer;
> > > 8<--------
> > > 
> > > There is nothing in these typedefs that guarantees that a gint will fit
> > > in a gpointer.
> > > 
> > > Some of the headers are generated when Glib is compiled, but not glib.h,
> > > so I suppose that the above is the same on the Alpha.
> > 
> > yes, and on the alpha sizeof(gpointer)=8, sizeof(gint)=4 and sizeof(glong)=8,
> > so an int can be stored in a pointer without lossage and a pointer can be
> > stored in a long without lossage, so my above summary still holds.
> > in fact, we haven't yet encountered a 32bit system (or 64bit system for that
> > matter) where sizeof(gpointer) would be less than 4, and i guess we never
> > will, so that pretty much makes up the above guarrantee.
> 
> Not really; it just means that it works on one more system, at least using
> one compiler. Since C makes no such guarantees, it really has to be
> "special cased" to be useful. As it is, it just looks like name space
> pollution: an obviously nonportable operation is renamed, hidden in a
> macro and claimed to be portable. Implementation-defined stuff like
> conversion between pointers and integral types is best handled by
> autoconf.

i don't frankly understand your argumentation. all the configure.in
tests glib uses have been written by the GLib team people, and we
have not yet encountered something to check for with regards to
storing ints in pointers. we can certainly test for sizeof(int)>=4
and sizeof(gpointer)<=sizeof(glong) (sizeof(long) is guaranteed to
be >= sizeof (int) by the C standards) and special case that in glib.h
or glibconfig.h, but i don't see a need for such a test when we know
that it'll always be passed successfully. we can simply "hard-code"
typedef void* gpointer; typedef int gint; typedef long glong; in that
case, which is in fact what we do right now.

so unless you present us with a 32 bit environment where sizeof (gpointer)
> sizeof (glong) or sizeof (gint) > sizeof (gpointer) holds true, we
can consider this issue pretty much settled.

> 
> Ulric
> 

---
ciaoTJ



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