Avoiding macro using 32 bits shift warning

Hi,

I use below macro
#define SFRX(Sfr,Msk) (Sfr=((Sfr & (~ ((Msk)>>8)) ) |(Msk)))
to simply both Set and Reset specified bits in some register.

If I write SFRX ( MyReg , 0x0100 ) this macro clears bit 0.
If I write SFRX ( MyReg , 0x0002 ) this macro set bit 1.
If I write SFRX ( MyReg , 0x0102 ) this macro clears bit 0 and sets bit 1 in one go whithout affecting other bits.

Now I would like to use this macro for a 32-bits system:
#define SREG(Reg,Msk) (Sfr=((Sfr & (~ ((Msk)>>32)) ) |(Msk)))

Although the compiler warns that shifting is too long it works fine.
(main.c(56): warning: #63-D: shift count is too large)

My question is: how do I prevent this warning to occur?

Thanks

Henk

Parents
  • Why not have a ClearSet(a,clear_bits,set_bits) macro instead, where there are no need for the macro to operate using twice as many bits as the variable?

    It also has the advantage that the user don't have to remember to split one of the arguments in the middle to figure out which value you invert and mask with, and which value you or in.

Reply
  • Why not have a ClearSet(a,clear_bits,set_bits) macro instead, where there are no need for the macro to operate using twice as many bits as the variable?

    It also has the advantage that the user don't have to remember to split one of the arguments in the middle to figure out which value you invert and mask with, and which value you or in.

Children
More questions in this forum