On Fri, Dec 13, 2002 at 04:41:06PM +0300, Andrey A. Chernov wrote: > On Fri, Dec 13, 2002 at 14:32:40 +0200, Ruslan Ermilov wrote: > > Pardon my ignorance here, but the following fragment > > returns -1, doesn't it? > > > > #include <stdio.h> > > void > > main(void) > > { > > int i; > > > > i = (unsigned char)1 - (unsigned char)2; > > printf("%d\n", i); > > } > > It very depends on compiler, i.e. does it implements "value preseving" or > "unsigned preserving" for 'char' type conversions. Or ANSI C vs. common C > mode. Better be safe for both. > > Read 6.10.1.1 section here: > http://wwwrsphysse.anu.edu.au/doc/DUhelp/AQTLTBTE/DOCU_067.HTM > This is handled by the -traditional flag of gcc(1):
: `-traditional' : : Attempt to support some aspects of traditional C compilers. : Specifically: : [...] : : * Integer types `unsigned short' and `unsigned char' promote to : `unsigned int'. With -traditional, the code I quoted still produces -1. In any case, this section doesn't apply to this case because no conversion described in section 6.10 is ever done here, since both operands are of the same type, "unsigned char". Cheers, -- Ruslan Ermilov Sysadmin and DBA, [EMAIL PROTECTED] Sunbay Software AG, [EMAIL PROTECTED] FreeBSD committer, +380.652.512.251 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age
msg48646/pgp00000.pgp
Description: PGP signature