The bitwise operation doesn't work with an expression
but only with a variable:
The folowing simple example doesn't work:
x = 0x04 << 16;
It must be converted into:
x = 0x04;
x <= 16; // works
This fact disables use of macros like this:
#define SET_FLG1(x) (x & 0x3f) << 5 // doesn't work
which would be a one solution of another bug of
OnboardC that it doesn't work the bit fields (see Bit
fields bug). So the only solution is to use a function
(instead of using macros).
If you have any explanations or ideas of how to solve
this problem or if I make any mistake, please write me
to azx@centrum.cz.
Logged In: YES
user_id=574706
Originator: NO
Is this a BUG according to K&R?
can some sonfirm this?
Logged In: YES
user_id=574706
Originator: NO
Is this a BUG according to K&R?
can some sonfirm this?
Logged In: YES
user_id=583634
Originator: NO
I can't confirm whether OnBC supports this or not, or what the original poster means by "Doesn't work": Doesn't compile/produces bad code/produces incorrect answer.
I can confirm that this is perfectly legal as per K&R A7.8 (Shift Operators):
"The shift operators << and >> group left-to-right. For both operators, each operand must be integral, and is subject to the integral promotions. The type of the result is that of the promoted left operand. The result is undefined if the right operand is negative or greater than or equal to the number of bits in the left expression's type.
shift-expression:
additive-expression
shift-expression << additive-expression
shift-expression >> additive-expression
..."
Also note, however, that the original poster's translation of it is incorrect:
x = 0x04 << 16;
should be translated
x = 0x04;
x = x << 16;
*not*
x <= 16;
Logged In: YES
user_id=574706
Originator: NO
hmm, so what sdhould we do with this Bug-Report? make it a Task, Close it, or just leave it?
Logged In: YES
user_id=583634
Originator: NO
I say we leave this open. It's covered under task C016: OnBC: K+R Compliance