I am using a structure such as
struct IF_ID {
int PC;
string instruction;
};
and then in the
int main()
{
IF_ID stage1;
stage1.PC=0;
FETCH(stage1);
DECODE(&stage1);
return 0;
}
When I passe stage1 in the FETCH(stage1) function it works fine, the thing is that i need the values that has been calculated in the FETCH(stage1) to be used again in the second function DECODE(stage1)
so if the stage1.PC is equal to 5 for example i need to reuse it in the DECODE(stage1) function how can i do that??
You’re passing the struct to FETCH() by value.
This means it is COPIED to the function.
If you want the actual struct to be passed, you need the method to receive its pointer or reference:
By reference:
pointer to struct:
If you use by reference, the inner function semantics wont change.