AnsweredAssumed Answered

Error upon incrementing 8bit variable using CW10.7

Question asked by gellertbalogh on Nov 7, 2018
Latest reply on Nov 15, 2018 by Jorge Antonio Alcala Vazquez

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:

original structure


The segment of the code in question:

code segment triggering the error

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:

inc.w used on 8bit variable

(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

different variable is used in the if statement

This is what I get:

both variable incremented using inc.b

(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:

declaring the variable using :8 postfix


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




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'.