VS Arduino
Visual Micro >> General Board >> Trouble with static bool in a .cpp file?
https://www.visualmicro.com/forums/YaBB.pl?num=1561303573

Message started by PoutinePlatter on Jun 23rd, 2019 at 3:26pm

Title: Trouble with static bool in a .cpp file?
Post by PoutinePlatter on Jun 23rd, 2019 at 3:26pm
Anybody every see a static bool in a .cpp file not work properly ?

I have a declare and int as:

Code (c++):
static bool cycledown = false;


Essentially it seems to be re-initialized to 'false' each and every time the function is called.

If I use a static int, and similarly mystaticint = 0, then it does the same thing - variable gets re-init'd if the init value is 0. 

My workaround is use a static int aka myfauxbool and make 1=false and 69=true (arbitrary dumb number), and thjen THIS works fine, variable value is persistent.  I convert that faux-bool to true/false on entry each time then the code works great.

But its weird. Anybody can explain?

Title: Re: Trouble with static bool in a .cpp file?
Post by Visual Micro on Jun 23rd, 2019 at 5:47pm
I guess this is down to the tool chain you are using. Worth asking on the Arduino forum because there are a lot of coders there.

Any reason why you don't use a .h?

Title: Re: Trouble with static bool in a .cpp file?
Post by Visual Micro on Jun 23rd, 2019 at 5:48pm
I guess this is down to the tool chain you are using. Worth asking on the Arduino forum because there are a lot of coders there.

Any reason why you don't use a .h?

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.