Path: utzoo!utgpu!jarvis.csri.toronto.edu!torsqnt!tmsoft!masnet!canremote!mark.levy From: mark.levy@canremote.uucp (MARK LEVY) Newsgroups: comp.lang.c Subject: Re: is this broken or what? Message-ID: <90020407120313@masnet.uucp> Date: 4 Feb 90 10:23:00 GMT Organization: Canada Remote Systems Limited, Mississauga, ON, Canada Lines: 35 dP>Are we to infer from this discussion that the ANSI standard requires dP>comparisons like the one we are talking about to work properly? That dP>is, what is the prescribed behavior of dP> int i=MAXINT, j=(-MAXINT); dP> if (i > j) printf ("foo"); dP>Since i-j is negative, not positive, I would expect most compilers dP>*not* to print "foo". I am not up on the ANSI standards that have been proposed, but as I recall, the K&R standard was 0 == FALSE and anything else == TRUE. dP>I don't even know what happens when you compare an unsigned value to a dP>signed value. That is, in the test dP> unsigned int i; dP> if (i >= 0) ... The use of 2's complement will avoid any kind of problem of positive or negative zero. A compiler might flag an incompatible data type comparison here. My guess is that if the high order bit in i is set, the expression will evaluate false, provided that it compiled. dP>is i converted to a signed type before the comparison is performed? dP>This could certainly make a mess if i is all ones. Don't ever assume anything about type conversions. If you're not sure, use pleanty of casts and parens. Mark --- ~ DeLuxe 1.11a18 #3019 ~ QNet 2.04a:NorthAmeriNet: Sound Advice BBS ~ Gladstone ~ MO