弱问一个C语言的问题:关于函数指针,在线等
结构体定义:typedef struct {_iqAs; // Input: phase-a stator variable
_iqBs; // Input: phase-b stator variable
_iqAlpha; // Output: stationary d-axis stator variable
_iqBeta; // Output: stationary q-axis stator variable
void(*calc)(); // Pointer to calculation function
} CLARKE;
typedef CLARKE *CLARKE_handle;
/*-----------------------------------------------------------------------------
Default initalizer for the CLARKE object.
-----------------------------------------------------------------------------*/
#define CLARKE_DEFAULTS { 0, \
0, \
0, \
0, \
(void (*)(Uint32))clarke_calc }
/*------------------------------------------------------------------------------
Prototypes for the functions in CLARKE.C
------------------------------------------------------------------------------*/
void clarke_calc(CLARKE_handle);
=======================================================
函数定义:
void clarke_calc(CLARKE *v)
{
v->Alpha = v->As;
v->Beta = _IQmpy((v->As + _IQmpy(_IQ(2),v->Bs)),_IQ(0.57735026918963)); // 1/sqrt(3) = 0.57735026918963
}
这里初始化赋值里面的(void (*)(Uint32))clarke_calc 里的(Uint32)有什么用?怎么确定的?我直接用(void (*))clarke_calc 行不行?为什么?谢谢 还有一点不明白,clarke_calc是一个已经定义了的函数名呀,函数名本身不就是代表地址吗?为什么还要这么多强制类型转换? 将clarke_calc强制类型转换成(void (*)(Uint32)),这个 (void (*)(Uint32)) 表示的是一个返回void类型的\参数为一个Uint32 类型数据的 函数的指针. “参数为一个Uint32类型数据的”
原来如此。。。。。
3x very much 不是那么回事嘛,看这个:
typedef struct { int16 Txdata;
void (*init)();
void (*dsend)();
}SCI;
typedef SCI *SCI_handle;
#define SCI_DEFAULTS {{0,0,0,0,0,0,0,0}, \
(void(*)(Uint32))scia_init,\
(void(*)(Uint32))scia_send \
}
void scia_init(void);
void scia_send(SCI_handle); (void (*)(Uint32))clarke_calc
这里是将clarke_calc强制转换成一个(void (*)(Uint32))类型的函数指针,它指向的函数以Uint32为参数,void为返回类型 mark Uint32似乎应该是指指针数据的位宽吧?
页:
[1]