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
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
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
JohnWatson
Site Admin
Joined: Thu May 24, 2012 12:15 pm Posts: 380
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!
Users browsing this forum: No registered users and 1 guest
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