Re: [gtk-list] Re: gpointer and callbacks



From: dross <dross@melbpc.org.au>
Subject: [gtk-list] Re: gpointer and callbacks
Date: Wed, 14 Oct 1998 21:24:02 +0000

> Thanks Petter,
> 
> Your explanation has made everything much clearer. I made 2 global constants as IDs
> for the devices, and I passed these to the callback function and it seems to work
> now - does this look ok?

Yes. It looks like it should work.

> const int  MIXER_VOLUME = SOUND_MIXER_VOLUME, MIXER_MIC = SOUND_MIXER_MIC;
> 
> void setup_window (GtkWidget * parent)
> {
>     .
>     .
> 
>   device = SOUND_MIXER_VOLUME;
>   volume = get_level(device);
>   vol_adj = (GtkAdjustment*)gtk_adjustment_new ((volume & 0x000000ff), 0, 100, 1, 1,
> 0);
>   hscale = gtk_hscale_new (GTK_ADJUSTMENT (vol_adj));
>   gtk_signal_connect (GTK_OBJECT (vol_adj), "value_changed",
>         GTK_SIGNAL_FUNC (adjust_level), (gpointer)&MIXER_VOLUME);
>     .
>     .
> }
> 
> Also is *(int*)data the right way to de-reference the pointer.

Yes, cast to int pointer then de-reference. I don't have a C ref
manual at my hands right now, but the following works (gcc 2.7.2.3):

#include <stdio.h>

int main() {
  int val = 10;
  void* ip;
  int val2;

  ip = (void*)&val;
  val2 = *(int*)ip;

  printf("val is %d, val2 is %d\n",val,val2);
}

However, I'm quite new to gtk, but my impression is that there are
zillions of macros to do type casting. Maybe there's one for casting
gpointer to gint pointer? val2 = *GPOINTER_TO_GINTPOINTER(ip);

Petter
-- 
________________________________________________________________________
Petter Gustad     8'h2B | (~8'h2B) - Hamlet     http://home.sol.no/~pegu
#include <stdio.h>/* compile/run this program to get my email address */
int main(void) {printf ("pegu\100computer\056org\nmy opinions only\n");}



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