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



On Thu, 4 Mar 1999, Lars Hallberg wrote:

> On Wed, Mar 03, 1999 at 06:50:19PM -0800, Theodore Roth wrote:
> > This looks kinda dangerous to me:
> > 
> > Lars Hallberg wrote:
> > > > GTK_SIGNAL_FUNC(handle_value),(gpointer)???);
> > >   GTK_SIGNAL_FUNC(handle_value),(gpointer) value);
> > > >
> > > > the_value=??????data;
> > >   the_value= (int) data;
> > 
> > Correct me if I'm wrong, but doesn't this make the assumption that
> > sizeof(int)==sizeof(void *)? And wouldn't this cause problems on systems
> > which the assumption is false, e.g. 64 bit systems? I feel the safer way
> > to do it is to pass the reference, as in (gpointer)&value.
> 
> You probably right (i got 0 64 bit experiens). Hovewer i think glib
> promis some things to work (probably shuld use gint32 insted of int -
> but that migt be problem on some 16 bit mashines ;-)
> 
> This in the start of main will make the problem menefest whenever there:
> 
>    if(sizeof(int)>sizeof(gpointer))
> 	exit();

I had not use C on various platforms but:
* sizeof(int) is far from sizeof(gpointer), generaly they can be untied,
'cos if machine have a byte as memory unit it'll be number of bytes per
int, and this is set 'by software' -- with compiler. sizeof(void*) is
number wich depends on architecture. More if you have there are crazy
systems (e.g. DOS) were sizeof(int a)!=sizeof(int b) if a,b are stored in
different memory parts. So your condition will just break program on some
OSes. Anyway, if somebody wanna use it, it should be put to configure
script.
* casting scalar type (int) to pointer (gpointer) is not good idea anyway.

_____
Alexander Kotelnikov
Saint-Petersburg, Russia
mailto:sacha@ak2614.spb.edu



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