Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Trouble with static bool in a .cpp file? (Read 130 times)
PoutinePlatter
Junior Member
**
Offline



Posts: 23
Trouble with static bool in a .cpp file?
Jun 23rd, 2019 at 4: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?
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: Trouble with static bool in a .cpp file?
Reply #1 - Jun 23rd, 2019 at 6: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?
Back to top
 
WWW  
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: Trouble with static bool in a .cpp file?
Reply #2 - Jun 23rd, 2019 at 6: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?
Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print