Re: passing args



Title: Re: passing args

This message uses a character set that is not supported by the Internet Service.  To view the original message content,  open the attached message. If the text doesn't display correctly, save the attachment to disk, and then open it using a viewer that can display the original character set. <<message.txt>>

Received: from [10.2.30.109] (LOCALHOST [10.2.30.109]) by exchange.office.etoys.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21)
	id XDVXQXAT; Sun, 19 Nov 2000 20:18:59 -0800
Date: Sun, 19 Nov 2000 21:20:24 -0800 (PST)
From: Rasoul Hajikhani <rhajikhani exchange office etoys com>
X-Sender: rhajikhani localhost localdomain
To: "DINH V. =?iso-8859-1?Q?Ho=E0?=" <dinh enserb fr>
cc: Juergen Boemmels <boemmels physik uni-kl de>, 
    gtk-list <gtk-list gnome org>
Subject: Re: passing args
In-Reply-To: <3A13296B A8A89CE5 enserb fr>
Message-ID: <Pine LNX 4 10 10011192117440 2040-100000 localhost localdomain>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN
Content-Transfer-Encoding: QUOTED-PRINTABLE

I say, I have done what you have said, that is I pass a reference to a=20
data structure an I get the following warning
interface.h:281: warning: passing arg 2 of `gtk_timeout_add' from
incompatible pointer type
and here is what I am doing:
timer =3D gtk_timeout_add (100, progress_timeout, hybrid);
where hybrid is a data structure...
so what's the deal...
-r

On Thu, 16 Nov 2000, DINH V. [iso-8859-1] Ho=E0 wrote:

> Juergen Boemmels wrote:
> >=20
> > "DINH V. Ho=E0" <dinh enserb fr> writes:
> >=20
> > > to call the function, you do the following :
> > >
> > > {
> > >    struct struct_arg1_arg2 data;
> > >    data->arg1 =3D arg1;
> > >    data->arg2 =3D arg2;
> > >    gtk_timeout_add(interval, function, &data);
> > > }
> >=20
> > I'm not sure, but this won't work.
> > You alloc the data on the stack, register a pointer to this, add leave
> > the function destroying this part of the stack. But it also may even
> > work in several cases. Those bugs are realy hard to find.
> >=20
> > When your timeout occurs, you may get a segfault, because the
> > stackframe is no longer valid.
> >=20
> > A possible way would be
> > {
> >   struct struct_arg1_arg2 *data;
> >=20
> >   data =3D malloc (sizeof (struct struct_arg1_arg2));
> >   g_assert (data !=3D 0);
> >   /* init data */
> >   gtk_timeout_add (interval, function, &data);
> > }
> >=20
> > function (struct struct_arg1_arg2 *data)
> > {
> >   /* do something with data */
> >   free (data);
> > }
>=20
> ok, the way I gave won't work but yours won't work too.
>=20
> because, data will be freed as much as the function is called. (the
> function is called periodically with gtk_timeout_add).
>=20
> then the a better solution is=20
>=20
>  {
>    struct struct_arg1_arg2 *data;
> =20
>    data =3D malloc (sizeof (struct struct_arg1_arg2));
>    g_assert (data !=3D 0);
>    /* init data */
>    gtk_timeout_add (interval, function, &data);
>  }
> =20
>  function (struct struct_arg1_arg2 *data)
>  {
>    /* do something with data */
>    // no free
>  }
>=20
>=20
> don't forget to free the data at the end of the program or when the
> timeout
> callback will be stopped.
>=20
> --=20
> Hoa
>=20
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>=20


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