my code is 110% correct; eg no errors and runs properly. see.
int _val; int myfunc2(int val) { _val = val; return _val; }; int Bar(int val) { return _val + val + 1; }; void myfunc1(int val) { _val += Bar(val); }; etc etc etc
it doesnt give me the right answer sometime.
HEEEEEEEELLLLLLLPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
it doesnt give me the right answer sometime
The sometimes part usually points to resource sharing conflicts in a system with multitasking or interrupts. But you'll have to provide some information if you want to get meaningful help.
Watchout for functions modifying global variables and called as part of expressions that contains same global variables.
You have to look out for evaluation order problems.
And depending on your code, you may have to consider aliasing problems too - multiple access ways to the same variable making the compiler fail to notice that one access way changes the variable while the compiler sees the other access way and think the variable must be unchanged.
Think twice about your use of global variables.
Some people would say that the code is bad simply because it uses global variables!
I don't agree that globals are inherently bad but, as Per says, they certainly do bring issues that you have to consider carefully...