Article View: comp.std.c
Article #4Re: What is the value of `(unsigned) -1' ??
From: Jos Horsmeier
Date: Tue, 27 Oct 1992 11:02
Date: Tue, 27 Oct 1992 11:02
33 lines
1927 bytes
1927 bytes
In article <1992Oct27.071744.4871@netcom.com> rfg@netcom.com (Ronald F. Guilmette) writes: | |The Subject line say it all. I've read section 3.2.1.2 and it appears that |the authors of the ANSI/ISO C standard went out of their way to define |the value of every conceivable arithmetic conversion *except* the conversion |of a negative signed integral value to an unsigned integral value of the |same size. | |If anyone has evidence to the contrary, please share it. (Please don't |provide opinions... provide citations instead. Thanks.) I think the standard defines rather well what happens to it: 3.2.1.2 Signed and unsigned integers `When a signed integer is converted to an unsigned integer with equal or greater size, if the value of signed integer is nonnegative, its value is unchanged. Otherwise: if the unsigned integer has greater size, the signed integer is first promoted to the signed integer corresponding to the unsigned integer; the value is converted to unsigned by adding to it one greater than the largest number that can be represented in the unsigned integer type.' On (normal?) two complement implementations nothing happens, i.e. the bit pattern remains the same as it was. If the size of an unsigned int is larger than the size of a signed int, there will occur sign bit extension, e.g. sizeof(int) = 2; sizeof(unsigned int) = 4. -1 (0xffff) -> -1 (0xffffffff) -> 0xffffffff + 0x100000000 = 0xffffffff kind regards, Jos aka jos@and.nl
Technical Details
Message-ID:
<3745@dozo.and.nl>Path:
arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sun4nl!and!josReferences:
<1992Oct27.071744.4871@netcom.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sun4nl!and!jos From: jos@and.nl (Jos Horsmeier) Newsgroups: comp.std.c Subject: Re: What is the value of `(unsigned) -1' ?? Message-ID: <3745@dozo.and.nl> Date: 27 Oct 92 11:02:35 GMT References: <1992Oct27.071744.4871@netcom.com> Organization: AND Software BV Rotterdam Lines: 33