我是 C 新手,有几个关于将结构体值放入函数以及声明函数的正确方法的问题。
在我的 common.h 中我定义了
extern struct ddrautocal;
int get_eeprom_vals(uchar); // is this the correct declare the function?
在calibration.c中,我定义了我的结构并更改了一些设置的一些值(未显示)
#include <common.h>
struct ddrautocal {
u32 wdtr;
u32 clkp;
u32 rdcc;
};
在 proc.c 中
#include <common.h>
int get_eeprom_vals(struct ddrautocal *cal){
// I'd like to access cal.wdtr and cal.clkp
}
我是一个彻头彻尾的傻瓜,我知道,但我正在努力变得更好。我一整天都在努力让它工作,想知道我是否在 common.h 中正确声明了该函数,以及访问位于 proc.c 中的 get_eeprom_vals 函数中的 ddraautocal 结构的正确方法是什么?任何帮助都会不胜感激。谢谢!
最佳答案
int get_eeprom_vals(uchar);
签名错误..应该是:
int get_eeprom_vals(struct ddrautocal *cal);
因此前向声明和函数定义的签名匹配。
要访问成员,您需要:cal->wdtr
, cal->clkp
或(*cal).wdtr (*cal).clkp
-> 使用指针间接运算符。 * 是间接运算符和句点(点)的组合,用于访问该字段。
我还认为你需要 #include "common.h"
而不是#include <common.h>
因为 common.h 不是系统头。
关于c - 定义函数并传递结构值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13148204/