Jump to content
Sign in to follow this  
SnakeByte

Static Variable Bug?

Recommended Posts

Heya,

I *think* I've found a compiler bug in how code is translated to asm with regard to static variables. (using boostc 1.6 Alpha)

 

It's my understanding that static variables that are initialized are only supposed to be initialized once.

 

Here's example code:

 

char staticVariableTest()

{

// initialization should only happen once

static char a = 0;

return a++;

}

 

The asm, however, shows that the variable will be cleared each time through:

 

staticVariableTest

; { staticVariableTest ; function begin

BCF STATUS, RP0

BCF STATUS, RP1

CLRF staticVariableTest_2_a

INCF staticVariableTest_2_a, F

MOVF staticVariableTest_2_a, W

MOVWF CompTempVarRet0

RETURN

; } staticVariableTest function end

 

Here's the code I used to test this function:

 

void main()

{

char i = 0;

char total = 0;

for (i=0;i<10;i++)

{

total = staticVariableTest();

}

// break point here.

// total should equal 9;

// but instead shows 1

char result = total;

}

 

p.s. thanks for all the work you've done... I can imagine it's been a tough ride so far. If static variables aren't supported yet, I appologize for not learning about this before posting.

Share this post


Link to post
Share on other sites

This bug has been fixed. Took a while to sort it out but now compiler fully supports static locals. Fix will be available in BoostC 1.7 release (or update).

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...