This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to Init Local Static Variable

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 ?

0