We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Dear All,
I write a function with Local Static Variable. But can't get its value initiated.
void analyzeInputs() { static uByte TimeState = 0; // Init Value switch (TimeState) { case 0 : TimeState++; // MORE CODE HERE ... break; case 1 : TimeState++; // MORE CODE HERE ... break; case 2 : TimeState = 0; // MORE CODE HERE ... break; } }
When go to debug mode, at first, it always jump to Case 1 (not 0), mean : no value initiated.
But if I change, declare "TimeState" as Global Var then its value init fine.
-> Is it because the Keil won't init any static local variable during Start-Up Code ?
ur case 0 and case 1 r the same so compilar just did some opttimizeration.
no problem.
next question plz.
Always yo're freind
Zeusti.
(writing freindly code for real poeple)
Note that this doesn't just apply when the codes are identical - the compiler can also spot when they contain common section(s), and may combine those parts...
it always jump to Case 1 (not 0), mean : no value initiated.
First of all, you don't really know where it jumped to. The compiler may just be cleverer than you imagined it could be.
Second, why do you think you have to inspect execution order to see what value your switch() variable has? Just inspect the variable itself!
<quote>Note that this doesn't just apply when the codes are identical</quote>
undoubtebly.
u can learn some simple optimisation words here
http://www.keil.com/support/man/docs/c51/c51_ap_opt_general.htm
Always yo're freind.
(putting supercomputer power into ur sporrans)
Thanks all !