struct student{int age ,float score ,char sex}
//为结构体赋值
struct student stu={20 ,98.9 ,' w'}
看了上面就容易理解下面的语句:
typedef int (*over_time_func)();//函数指针
struct timer_func
{
over_time_func func;
};
struct timer_func tf ={func};
//
struct list
{
NodePtr node;//头指针,指向头结点
ushort datasize;//链表对应的数据单元所占内存的大小
ushort length;//链表list的长度
byte otype;//数据类型
};
typedef struct list List;
typedef List OverDayFuncList;
OverDayFuncList DAY_FUNC_LIST ={0};
struct timer_func
{
over_time_func func;
};
//时间过正时函数指针,正分、整时,整日,整月
typedef int (*over_time_func)();//函数指针
add_OverDayFunc(do_day_action);
void add_OverDayFunc(over_time_func func)
{
add_overfunc(TI_DAY,func);
}
void add_overfunc(enum TI_UNIT tu,over_time_func func)
{
struct timer_func tf ={func};
switch(tu)
{
case TI_SECOND:
SetNodeDataSize(&SECOND_FUNC_LIST,0,sizeof(struct timer_func));
Add2ArrayList(&SECOND_FUNC_LIST,&tf,NULL);
break;
case TI_MINUTE:
SetNodeDataSize(&MINUTE_FUNC_LIST,0,sizeof(struct timer_func));
Add2ArrayList(&MINUTE_FUNC_LIST,&tf,NULL);
break;
case TI_HOUR:
SetNodeDataSize(&HOUR_FUNC_LIST,0,sizeof(struct timer_func));
Add2ArrayList(&HOUR_FUNC_LIST,&tf,NULL);
break;
case TI_DAY:
SetNodeDataSize(&DAY_FUNC_LIST,0,sizeof(struct timer_func));
Add2ArrayList(&DAY_FUNC_LIST,&tf,NULL);
break;
case TI_MONTH:
SetNodeDataSize(&MONTH_FUNC_LIST,0,sizeof(struct timer_func));
Add2ArrayList(&MONTH_FUNC_LIST,&tf,NULL);
break;
default:break;
}
}
int do_day_action(void* args)
{
log_print(INFO,"do_day_action:delete 62 days ago(day freeze,month freeze,curve freeze) data! \n");
//é?3yêy?Y
//删除数据
delete_obsolete_data(0x50040200);
delete_obsolete_data(0x50060200);
delete_obsolete_data(0x50020200);
return 1;
}
static ListPtr get_func_list(enum TI_UNIT tu)
{
switch(tu)
{
case TI_SECOND:
return &SECOND_FUNC_LIST;
case TI_MINUTE:
return &MINUTE_FUNC_LIST;
case TI_HOUR:
return &HOUR_FUNC_LIST;
case TI_DAY:
return &DAY_FUNC_LIST;
case TI_MONTH:
return &MONTH_FUNC_LIST;
default:break;
}
return NULL;
}
void exec_over_timer_func(enum TI_UNIT tu)
{
ListPtr plist =get_func_list(tu);
if(plist ==NULL) return ;
NodePtr node =plist->node;
while(node !=NULL)
{
if(node->data !=NULL)
{
struct timer_func* ptf =(struct timer_func*)node->data;
ptf->func();
}
node = node->next;
}
}
exec_over_timer_func(TI_DAY);
//assign指定数据data间的赋值方法
NodePtr Add2ArrayList(ListPtr list, void *data, void (*assign)(void* dest, const void* src))
{
if(list==NULL) return NULL;
NodePtr node = (NodePtr)malloc(sizeof(struct node));
if(node ==NULL) return NULL;
node->data =malloc(list->datasize);
if(node->data ==NULL) return NULL;
node->next =NULL;
//设置结点的值
if(assign == NULL)//使用默认的逐位复制方式,即浅复制
memcpy(node->data,data,list->datasize);
else //使用用户定义的复制方式来复制数据
assign(node->data, data);
if(list->node ==NULL)
list->node =node;
else
{
NodePtr temp =list->node;
while(temp->next !=NULL)temp=temp->next;
temp ->next=node;
}
//把node的值连入list后,list的长度加1
++list->length;
return node;
}