View unanswered posts | View active topics It is currently Tue Sep 02, 2014 1:16 pm






Reply to topic  [ 3 posts ] 
local static variable problem 
Author Message
Rookie

Joined: Wed Nov 14, 2012 4:22 am
Posts: 2
Post local static variable problem
Code:
void test()
{
//if (1==1)
{
static int a = 0;
a++;
writeDebugStream("a= %d\n",a);
}
}


task main()
{
test();
test();
test();
}and will output:


produces the output

a= 1
a= 1
a= 1

where as it should be

a= 1
a= 2
a= 3

if the inner braces are removed it works properly.

this happens on both 3.54 and 3.55 beta, on vex
thanks
Steve


Wed Jan 16, 2013 5:57 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: local static variable problem
Yes, this is a known problem. I have reported it to the RobotC folks. Static variables is supposed to be initialized only once during compile time. It looks like RobotC actually generated code to initialize it at run-time.


Wed Jan 16, 2013 7:54 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 566
Post Re: local static variable problem
Thank you for the heads up on this one, we now have a BETA build (ROBOTC 3.59.0) that should fix this problem (link below). As with any BETA build, there may be unforeseen issues or bugs, and we ask that you please report any that you find either here in our Issues and Bugs forum or directly to us via support@robotc.net. Thank you in advance!


ROBOTC BETA 3.59.0 Download

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Mon Feb 25, 2013 12:00 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.