R
regis
Hello,
Suppose that some type of callback function is declared
to take a pointer to some struct as one of its argument.
Is it legal to implement the callback functions as
taking a void* for this argument.
=======================================
typedef struct Foo { int x; } Foo;
typedef void (*Func) (Foo*, void*);
void MyFunc (void* foo, void* user) {
/* void* instead of Foo* -> legal ?
*/
}
....
Func func= (Func) MyFunc;
Foo foo;
....
func (& foo, NULL);
======================================
Same question with:
typedef struct Foo1 { int x1; } Foo1;
typedef struct Foo2 { Foo1 foo1 ; int x2; } Foo2;
typedef struct Foo3 { Foo2 foo2 ; int x3; } Foo3;
typedef struct Foo4 { Foo3 foo3 ; int x4; } Foo4;
....
typedef void (*Func) (Foo1*, void );
void MyFunc (XXX foo, void* user) {
/* where XXX is void*, or Foo2*, ..., or Foo4*
* instead of Foo1*
* -> legal ?
*/
}
....
Func func= (Func) MyFunc;
Foo4 foo4;
....
func (& foo4, NULL);
=======================================
(The context is that I am sometimes fed up
with all those casts in gtk and I wonder if it is
legal to replace GtkWidget* arguments of callback functions
by void* directly in the signature of the callbacks)
Suppose that some type of callback function is declared
to take a pointer to some struct as one of its argument.
Is it legal to implement the callback functions as
taking a void* for this argument.
=======================================
typedef struct Foo { int x; } Foo;
typedef void (*Func) (Foo*, void*);
void MyFunc (void* foo, void* user) {
/* void* instead of Foo* -> legal ?
*/
}
....
Func func= (Func) MyFunc;
Foo foo;
....
func (& foo, NULL);
======================================
Same question with:
typedef struct Foo1 { int x1; } Foo1;
typedef struct Foo2 { Foo1 foo1 ; int x2; } Foo2;
typedef struct Foo3 { Foo2 foo2 ; int x3; } Foo3;
typedef struct Foo4 { Foo3 foo3 ; int x4; } Foo4;
....
typedef void (*Func) (Foo1*, void );
void MyFunc (XXX foo, void* user) {
/* where XXX is void*, or Foo2*, ..., or Foo4*
* instead of Foo1*
* -> legal ?
*/
}
....
Func func= (Func) MyFunc;
Foo4 foo4;
....
func (& foo4, NULL);
=======================================
(The context is that I am sometimes fed up
with all those casts in gtk and I wonder if it is
legal to replace GtkWidget* arguments of callback functions
by void* directly in the signature of the callbacks)