When making an expression in C51 with the format shown below:
#define VALUE ((0x3F << 24) | (0x1F << 16) | (0x01 << 1))
Results in a value of 0x00000002
The same results are attained when re-writing the expression as:
#define VALUE ((0x3F << 24) + (0x1F << 16) + (0x01 << 1))
The same result is also generated when re-writing as:
#define VALUE ((0x01 << 1) | (0x1F << 16) | (0x3F << 24))
I have also tried casting the whole expression with (unsigned long) and casting each of the three individual components with (unsigned long) and not seen a change of behavior.
When using an expression similar to the #define on the right hand side of an assignment statement to an unsigned long variable the compiler demonstrates the same incorrect behavior as shown above.
Is this issue something that we can get Keil to fix in C51 and issue an updated compiler?
Michael Karas
Thanks Pier, I'll give that a try.