Boolean Variables / Bit fields using CW 4.7 + PE 2.98 - signedness/Bit order problems?? [S12XDP512]

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

Boolean Variables / Bit fields using CW 4.7 + PE 2.98 - signedness/Bit order problems?? [S12XDP512]

1,287 Views
analogist
Contributor I
Hi Folks,

right now i encounter some problem that puzzles me: In my current project, i use some boolean variables and bit fields. In PE_Types.h there are also the #define's and typedef's needed for this (typedef unsigned char bool; #define TRUE 1;#define FALSE 0:smileywink:

But, and that's how the problems show up, on some occasion such a boolean variable, which should be either 0 or 1 decimal, but nothing else, shows as 128 (have seen other values as well, 50, 212, 192 and more) in the debugger, which is far from what i would expect.

On top of that (but maybe related) i have some unsigned chars (uint8_t to be exact) set up as bit fields in order to hold some flags. Right now i'm using only the 4 least significant Bits using constructs like "if (var & __CURRENT) { do_some(); var &= ~__CURRENT; }", __CURRENT being replaced by the preprocessor as stated by "#define __CURRENT 0x04" so as to have some more verbosity in the source. But even though i currently am working just on the lower 4 bits, the upper 4 bits of that unsigned char occasionally get set in some semi-random way, about half the time i see it, they're the given Pattern ~__CURRENT shifted by four bits to the left...
I checked and double-checked my code if i was somewhere did arithmetics instead of logical instructions (like adding some value instead of OR'ing a bit or subtracting instead of AND'ing the inverse) but haven't found any going over all the files (including those generated by ProcessorExpert) several times.

Any suggestions on this??


Message Edited by analogist on 2008-06-23 12:38 PM

Message Edited by analogist on 2008-06-23 12:48 PM
Labels (1)
0 Kudos
2 Replies

400 Views
CompilerGuru
NXP Employee
NXP Employee
Is the stack big enough, sounds like a stack overrun.

Daniel
0 Kudos

400 Views
analogist
Contributor I
Looks just like that, increased stack size and now it suddenly works as expected...

Thanks a bunch!
Florian
0 Kudos