中级会员
 
- 积分
- 304
- 金钱
- 304
- 注册时间
- 2015-10-16
- 在线时间
- 49 小时
|
20金钱
本帖最后由 aaa405944519 于 2016-6-13 17:33 编辑
typedef struct RampGen_t //定义结构体
{
int32_t count;
int32_t XSCALE;
float out;
void (*Init)(struct RampGen_t *ramp, int32_t XSCALE);
float (*Calc)(struct RampGen_t *ramp);
void (*SetCounter)(struct RampGen_t *ramp, int32_t count);
void (*ResetCounter)(struct RampGen_t *ramp);
void (*SetScale)(struct RampGen_t *ramp, int32_t scale);
uint8_t (*IsOverflow)(struct RampGen_t *ramp);
}RampGen_t;
#define RAMP_GEN_DAFAULT \ //宏定义结构体变量?可以嘛?
{ \
.count = 0, \
.XSCALE = 0, \
.out = 0, \
.Init = &RampInit, \
.Calc = &RampCalc, \
.SetCounter = &RampSetCounter, \
.ResetCounter = &RampResetCounter, \
.SetScale = &RampSetScale, \
.IsOverflow = &RampIsOverflow, \
} \
RampGen_t LRSpeedRamp = RAMP_GEN_DAFAULT; //定义结构体变量,然后把宏定义的值赋到结构体变量中
这个程序是我看别人程序看来得,请问c语言编译有问题吗?
|
最佳答案
查看完整内容[请看2#楼]
这种带.操作的初始化方法是C99的标准,具体能不能用得看编译器,可以确定的是,GCC是肯定可以用这种方法初始化结构体,只要在CFLAG中加入-std=c99就行.GCC还扩展了一种:操作,就是 成员:值.
KEIL中用的ARMCC,我试过,是不行的,就算是选择了C99也不行.
VS编译器也不行.
所以,如果你是用的GCC编译器,直接COPY就可以了.不是的话,就要改成顺序初始化的方式.[mw_shl_code=c,true]#define RAMP_GEN_DAFAULT \
{\
0, \
0, ...
|