Re: passing args



I like to write functions such as function_prime as a macro because they are so simple.  That way it doesn't take any runtime to call it.

-D

On Wed, 15 Nov 2000 16:48:54 DINH V. Hoà wrote:
 | ASF wrote:
 | > 
 | >     Hello,
 | > 
 | > I use the gtk_timeout_add function and my problem is that I need to pass
 | > 2 args to the function specified in gtk_timeout_add but it accepts only
 | > one arg for datas....
 | 
 | 
 | The idea is to pass a structure with these two arguments
 | 
 | when you have a function
 | 
 | void function(type1 * arg1, type2 * arg2)
 | {
 |  ....
 | }
 | 
 | 
 | you have to define a second function and a structure :
 | 
 | struct struct_arg1_arg2
 | {
 |    type1 * arg1;
 |    type2 * arg2;
 | };
 | 
 | void function_prime(struct struct_arg1_arg2 * arg)
 | {
 |    function(arg->arg1, arg->arg2);
 | }
 | 
 | to call the function, you do the following :
 | 
 | {
 |    struct struct_arg1_arg2 data;
 |    data->arg1 = arg1;
 |    data->arg2 = arg2;
 |    gtk_timeout_add(interval, function, &data);
 | }
 | 
 | -- 
 | Hoa
 | 






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