D
Denis Pithon
Hi, C lovers!
I stuck on an union problem
Here is snippet of my code
....
/* two pointers of function with repsectively one and two argues */
typedef int (*dce_sn_f)(dce_t*);
typedef int (*dce_io_f)(dce_t*, FILE*);
/* A union to store one of the previous declared type */
typedef union {
dce_sn_f sn; /* func with dce_t* argue */
dce_io_f io; /* func with dce_t* and FILE argues */
} dce_f;
....
typedef struct dce_slot_st {
dce_f f; /* may be dce_dn_t or dce_io_t */
const char *name;
} dce_slot_t;
....
static dce_slot_t *build_slot( dce_f fun, const char *name )
{
dce_slot_t *new_slot;
new_slot = utl_calloc( sizeof(dce_slot_t) );
if (new_slot) {
new_slot->f = fun; /* XXXXXX */
new_slot->name = name;
} else {
UTL_SYSERR( "cannot create new slot" );
return NULL;
}
return new_slot;
}
.....
dc->init = build_slot( stub_init, "stub_init" );
gcc detect an error on this last line and said:
" incompatible type for argument 1 of `build_slot' "
Does somedy show what is bad in my code
Does the expression (marked wih XXXXX in the code), look correct ? gcc
does not complain about it !
Thanks a lot
Denis
I stuck on an union problem
Here is snippet of my code
....
/* two pointers of function with repsectively one and two argues */
typedef int (*dce_sn_f)(dce_t*);
typedef int (*dce_io_f)(dce_t*, FILE*);
/* A union to store one of the previous declared type */
typedef union {
dce_sn_f sn; /* func with dce_t* argue */
dce_io_f io; /* func with dce_t* and FILE argues */
} dce_f;
....
typedef struct dce_slot_st {
dce_f f; /* may be dce_dn_t or dce_io_t */
const char *name;
} dce_slot_t;
....
static dce_slot_t *build_slot( dce_f fun, const char *name )
{
dce_slot_t *new_slot;
new_slot = utl_calloc( sizeof(dce_slot_t) );
if (new_slot) {
new_slot->f = fun; /* XXXXXX */
new_slot->name = name;
} else {
UTL_SYSERR( "cannot create new slot" );
return NULL;
}
return new_slot;
}
.....
dc->init = build_slot( stub_init, "stub_init" );
gcc detect an error on this last line and said:
" incompatible type for argument 1 of `build_slot' "
Does somedy show what is bad in my code
Does the expression (marked wih XXXXX in the code), look correct ? gcc
does not complain about it !
Thanks a lot
Denis