Hello Chen, I don't see why you assume BIT4 to be a signed char. I think it already is an int. But yes, after ~ it will certainly be an int.
Maarten > Hi All, > > I have the following code below, with "default" signed char type. > > ----------- > #define BIT4 0b00010000 > #define P_IO_Ctrl_Base 0x2080 > > #define P_IO_PortC_Data *(volatile unsigned char *) (P_IO_Ctrl_Base+0x1A) > > #define DrvGPIO_SetBit(GPIO,BITIO) GPIO |= BITIO; > #define DrvGPIO_ClrBit(GPIO,BITIO) GPIO &= ~BITIO; > > void main() > { > DrvGPIO_ClrBit(P_IO_PortC_Data,BIT4); > } > ---------- > > I add `--fverbose-asm` option to see more details on the codegen. What > I'm curious about is the code snipt below: > > ---------- > ld a,(#0x209A) > ; peephole 17 loaded a from (#0x209A) directly instead of using hl. > ; genCast > ; genAnd > and a, #0xEF > --------- > > Although the genCast doesn't emit code, I am wondering why we need a > casting here. So I study C integer conversion rules [1] a little bit, > and here is my reasoning. > > 1. BIT4 => signed char > > 2. ~BIT4 => int > > 3. and we now have the following situation, > > P_IO_PortC_Data &= ~BIT4 > ^^^^^^^^^^^^^^^ ^^^^^ > > unsigned char int > > | * > v > > int > > the reason we have genCast is because we have unsigned char to int > promotion. > > Am I right or wrong about the C integer conversion rules? :-) > > Thanks in advance. > > [1] > https://www.securecoding.cert.org/confluence/display/seccode/INT02-C.+Understand+integer+conversion+rules > > > Regards, > chenwj > > -- > Wei-Ren Chen (é³éä»») > Homepage: http://people.cs.nctu.edu.tw/~chenwj ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user