This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

A C51 Compiler Error!!

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

Parents Reply Children
No data