联合类型变量赋值---在表达式中,在函数争论中
C爱好者!
我坚持工会问题
这是我的代码片段
....
/ *两个指针的功能与repsectively一和两个争论* /
typedef int(* dce_sn_f) (dce_t *);
typedef int(* dce_io_f)(dce_t *,FILE *);
/ *用于存储之前声明的联合的联合输入* /
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; / *可能是dce_dn_t或dce_io_t * /
const char * name;
} dce_slot_t;
....
静态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(&无法创建新槽');
返回NULL;
}
返回new_slot;
}
.....
dc-> init = build_slot(stub_init," stub_init");
gcc在最后一行检测到错误并说:
" build_slot的参数1的不兼容类型"
somedy是否显示我的代码中有什么不好
是否表达式(标记为wih XXXXX中的代码),看起来正确吗? gcc
不会抱怨它!
非常感谢
Denis
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
Denis Pithon写道:
Denis Pithon wrote:
dc-> init = build_slot(stub_init," stub_init");
gcc在最后一行检测到错误并说:
build_slot的参数1的不兼容类型"
我的代码中有什么不好的东西
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
stub_init是未声明的。
-
pete
stub_init is undeclared.
--
pete
pete写道:
Denis Pithon写道:
Denis Pithon wrote:
dc-> init = build_slot(stub_init," stub_init");
gcc在最后一行检测到错误并说:
build_slot的参数1的不兼容类型"
我的代码中有什么不好显示
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
stub_init未声明。
stub_init is undeclared.
糟糕的是,stub_init声明得很好(只是忘记在邮件中复制)
我用下面的简单代码获得了相同的错误
#include< stdio.h>
#include< stdlib.h>
typedef int(* f1_t)( int);
typedef int(* f2_t)(int,char *);
typedef union {
f1_t f1;
f2_t f2;
} f_t;
typedef struct {
f_t fun;
const char *姓名;
} f_slot_t;
int my_func(int a)
{
返回a;
}
f_slot_t * do_work(f_t fun,const char * name)
{
f_slot_t * f = calloc( 1,sizeof(f_slot_t));
f-> fun = fun;
f-> name = name;
return f ;
}
int main()
{
f_slot_t * sl;
sl = do_work(my_func," my_func" );
返回0;
}
Badly, stub_init is well declared ( just forget to copy it in the mail)
I obtain the same error with the simpler code below
#include <stdio.h>
#include <stdlib.h>
typedef int (*f1_t)(int);
typedef int (*f2_t)(int, char*);
typedef union {
f1_t f1;
f2_t f2;
} f_t;
typedef struct {
f_t fun;
const char *name;
} f_slot_t;
int my_func(int a)
{
return a;
}
f_slot_t *do_work( f_t fun, const char *name )
{
f_slot_t *f = calloc( 1, sizeof(f_slot_t) );
f->fun = fun;
f->name = name;
return f;
}
int main()
{
f_slot_t *sl;
sl = do_work( my_func, "my_func" );
return 0;
}
Denis Pithon写道:
Denis Pithon wrote:
pete写道:
pete wrote:
Denis Pithon写道:
Denis Pithon wrote:
typedef union {
f1_t f1;
f2_t f2;
} f_t;
int my_func(int a)
{
返回;
}
f_slot_t * do_work(f_t fun,const char * name)
sl = do_work (my_func," my_func");
typedef union {
f1_t f1;
f2_t f2;
} f_t;
int my_func(int a)
{
return a;
}
f_slot_t *do_work( f_t fun, const char *name )
sl = do_work( my_func, "my_func" );
my_func isn''ta union。
do_work的第一个参数应该是一个联合。
-
pete
my_func isn''t a union.
The first argument to do_work, should be a union.
--
pete