A文件中调用B文件中含有结构体参数的函数

来源:互联网 发布:京东运营数据报表 编辑:程序博客网 时间:2024/06/11 12:52

问题描述:

 

A.h

{

extern void B_switch(inton);//头文件中引入B文件中调用的函数

}

 

A.c

{

#include<A.h>

......

A_a(){

int aa=0,bb=1;

if(aa)

B_switch(aa);//调用函数

else

B_switch(bb);

......

}

}

 

B.c

{

union b_propval {

int intval;

const char *strval;

int64_t int64val;

};

 

struct msm_otg {

struct usb_phy phy;

struct msm_otg_platform_data *pdata;

int irq;

…...

}

 

static struct msm_otg  *b_for_typec = NULL;//定义一个全局的结构体变量来作为调用的参数

static intb_set_property_usb(struct b_supply *psy, enum b_property psp, constunion b_propval *val);//为真正调用的函数

 

void B_switch(int on)//新定义的函数来调用上面的函数,里面有结构体的参数

{

union b_propval val;

val.intval = on;

b_set_property_usb(&b_for_typec->b_psy,B_SUPPLY_PROP, &val);//函数调用

}

b_probe()

{

struct msm_otg *motg;

b_for_typec = motg; //probe的时候需要对定义的结构体赋值,指向另一个结构体成员即可

motg->b_psy.name = "ub";

…...

}

}

0 0
原创粉丝点击