【发布时间】:2018-04-04 20:04:59
【问题描述】:
这是我当前代码的布局,
test.h
typedef struct{
int aa;
int bb;
int cc;
} ABC;
extern ABC XYZ;
void passValue(ABC DEF,int a, int b, int c);
void doSomething();
test.c
ABC XYZ;
void passValue(ABC DEF,int a, int b, int c){
DEF.aa = a;
DEF.bb = b;
DEF.cc = c;
}
void doSomething(){
...
...
passValue(XYZ,10,20,30);
}
但当我在主程序上调用doSomething() 时,该值仍为0(未更改)。我试着像对待@R Sahu 回答 this question 一样对待他们,
test.h
typedef struct{
int aa;
int bb;
int cc;
} ABC;
extern ABC XYZ;
void passValue(ABC * DEF,int a, int b, int c);
void doSomething();
test.c
ABC XYZ;
void passValue(ABC * DEF,int a, int b, int c){
*DEF.aa = a; //error
*DEF.bb = b; //error
*DEF.cc = c; //error
}
void doSomething(){
...
...
passValue(&XYZ,10,20,30);
}
ERROR : expression must have struct or union type
【问题讨论】:
-
你能添加给出
ERROR : expression must have struct or union type错误的代码吗? -
This question and its answers 应该可以帮助您入门。
标签: c struct operators parameter-passing