[英]how to use a struct member as argument
I am attempting to use a member of a struct call channels to be used in higher level functions. 我试图使用结构调用通道的成员在更高级别的功能中使用。 Is is possible to have only one argument?
可能只有一个论点吗?
typedef struct {
int size;
Port_PadDriver padDriver; //pad driver speed
UserConfig *pinTable;
Port_Mode defaultmode;
Port_State defaultstate; //set, reset, toggle port
} DefaultConfig;
typedef struct {
uint32 Channel;
Port_Pin *pin;
Port_Mode mode;
Port_State state; //set, reset, toggle port
} UserConfig;
void IO_init(void) {
DefaultConfig defaultConfig;//create object
initconfig(&defaultConfig);//set init settings
userConfig(&defaultConfig);//overwrite settings with users settings with
a struct array
}
is it possible to create a IO_SetPinHigh(int channelnum); 是否可以创建IO_SetPinHigh(int channelnum); to be used in the IO_init(void) to change specific pins.
在IO_init(void)中使用以更改特定的引脚。
You can refer to struct members with the .
您可以使用引用结构成员
.
operator. 运营商。 By doing this, you can reference this member individually like any other variable:
这样,您可以像其他任何变量一样分别引用此成员:
IO_SetPinHigh(defaultConfig.channel);
Of course, if you want to modify this variable, you'll have to pass a pointer to it: 当然,如果要修改此变量,则必须将指针传递给它:
IO_SetPinHigh(&defaultConfig.channel);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.