Re: Typecast error



Dwight Tuinstra <tuinstra northnet org> writes: 
> You're right about a pointer to random data.  But casting
> pointers to ints, and vice-versa, has always seemed to me
> a horrible abuse of the type system (I guess I've been 
> overly influenced by contact with the ML language's Vorlon-
> strict typing).  It would seem that the above code assumes 
> that sizeof(gpointer) == sizeof(gint), to prevent data loss;
> is this guaranteed in gtk?

The GPOINTER_TO_INT()/GINT_TO_POINTER() macros just assume that
sizeof(void*) >= sizeof(int) which is pretty guaranteed.
If you simply cast to/from int using a plain C cast, you're right it
isn't portable.

> Would simply declaring dummy_int static or external solve
> the problem?  I'd be much more comfortable with that, even
> though it does introduce an extraneous variable.

Sure, you could do that.

> While we're on this topic, what is the right way to declare
> and pass an array of GtkObjects (in my case, GtkAdjustments)
> in a signal_connect/callback situation?  (I have an adjustment
> whose value depends on the value of several other adjustments).

You would normally need to allocate memory for the array, and then
free it somehow; a good way is to use gtk_signal_connect_full().

Or you could store each adjustment with gtk_object_set_data().

Havoc




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