Here is the layout of my current code,
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);
}
but when I call doSomething()
on the main program, the value is still 0 (not changed). I've try to treat them just like @R Sahu answer on 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