Hi,

> warning 180: using ~ on bit/bool/unsigned char variables
> can give unexpected results due to promotion to int
>
> The corresponding codes are:
> ======================================
>    54 void motor_switch_ori()
> -  55 {
> |  56         mori = ~mori;
> |  57 }
> ======================================
> the asm code generated by sdcc is:
> ======================================
>   467 _motor_switch_ori:
>   468 ;       motor_control.c:56: mori = ~mori;
>   469         setb    _P1_6
>   470         ret
> ======================================

You want to use "mori = !mori;" (logical NOT) rather than "mori = ~mori;"  
(bitwise NEGation), as the latter requires promotion to int (as per the C  
standard). You get:
   mori == 0 ==> ~mori == ~0 == 0xFFFF != 0 ==> mori = 1
   mori == 1 ==> ~mori == ~1 == 0xFFFE != 0 ==> mori = 1
which explains the setb instruction. You have been warned ...

> which is definitely not what I want. What could I do to reverse a bit?  
> Or it's a compiler's bug?

It's the standard compliant implementation, no bug here.

Best regards

Raphael

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to