Error upon incrementing 8bit variable using CW10.7

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error upon incrementing 8bit variable using CW10.7

858 Views
gellertbalogh
Contributor I

Hello folks,

I have encountered a strange problem while using CodeWarrior v10.7 with S12.

TLDR: under certain circumstances the increment operator (++) used on a 8bit uint compiles to inc.w and therefore the variable allocating the next byte in the memory gets incremented.

The structure containing the variables:

struct.png

The segment of the code in question:

code.png

test_var is a variable mirroring all the operations of the FilterCounter. The only difference is, that it is declared as a static uint8 inside of the function, while the structure from above is declared as static in the .c file (outside of any function)

So, if I compile the code I get the following:

incw.png

(test_var++ is also there, but it is in a different address)

 

The reason because I do think this is a bug is, that if I switch the if statement to the one containing test_var

code2.png

This is what I get:

incb.png

(also, it does not need to jump in order to increment the second variable)

It is possible to force the 8-bit behaviour by declaring the variable as

uint8 DryRunFilterCounter:8;

In this case the code compiles to the following, independent of which of the if condition are being used:

uint8_8.png

As for now, I can go with the latter, but I do not think this would be an intended behaviour. Can anyone reproduce this?

Cheers,

As for the screenshots; I know it is strange, but my company guidline does not allow me to share source code, in any form. This is already 'grey zone'.

0 Kudos
Reply
1 Reply

730 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi gellertbalogh

Could you share a simple project to reproduce this behavior?

Best regards

Jorge Alcala

0 Kudos
Reply