Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Trouble with static bool in a .cpp file? (Read 1131 times)
PoutinePlatter
Junior Member
**
Offline


Posts: 23
Joined: Jun 16th, 2019
Trouble with static bool in a .cpp file?
Jun 23rd, 2019 at 3:26pm
Print Post  
Anybody every see a static bool in a .cpp file not work properly ? 

I have a declare and int as:
Code (C++)
Select All
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
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Trouble with static bool in a .cpp file?
Reply #1 - Jun 23rd, 2019 at 5:47pm
Print Post  
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
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Trouble with static bool in a .cpp file?
Reply #2 - Jun 23rd, 2019 at 5:48pm
Print Post  
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 TopicPrint