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...
<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)