From: Philipp K. K. <pk...@sp...> - 2013-01-12 16:53:47
|
On 12.01.2013 15:53, Vaclav Peroutka wrote: > Hello, > > I am currently playing with comparison. I found that if I compare char > and uchar, both operands are promoted to int and then compared. This is > in iCode, as well and I am getting message "warning 185: comparison of > 'signed char' with 'unsigned char' requires promotion to int". > > But when I compare int with uint, no warning is printed and int is > silently casted to uint: > sign_compare.c(l23:s12:k15:d0:s0) iTemp8 [k14 lr12:13 so:0]{ ia0 > a2p0 re0 rm0 nos0 ru0 dp0}{volatile-unsigned-int xdata} := iTemp6 [k12 > lr10:12 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{volatile-int xdata} > sign_compare.c(l23:s13:k16:d0:s0) iTemp9 [k15 lr13:14 so:0]{ ia0 > a2p0 re0 rm0 nos0 ru0 dp0}{char fixed} = iTemp8 [k14 lr12:13 so:0]{ ia0 > a2p0 re0 rm0 nos0 ru0 dp0}{volatile-unsigned-int xdata} > iTemp7 [k13 > lr11:13 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{volatile-unsigned-int xdata} > > Is there any possibility to extend icode generator to cast such operands > to signed 3 bytes and then signed comparison ? And some warning message > ? The same probably applies to long and ulong. No. The current behaviour is what the standard mandates. See section 6.3.1.1 of the C11 standard. I have no idea, why we have a warning for comparison of char and unsigned char though. Comparing them seems like a perfectly sensible thing to do. Philipp |