ROBOTC.net forums
http://www.robotc.net/forums/

local static variable problem
http://www.robotc.net/forums/viewtopic.php?f=63&t=5374
Page 1 of 1

Author:  stevedh [ Wed Jan 16, 2013 5:57 am ]
Post subject:  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

Author:  MHTS [ Wed Jan 16, 2013 7:54 am ]
Post subject:  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.

Author:  JohnWatson [ Mon Feb 25, 2013 12:00 pm ]
Post subject:  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

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/