Article View: comp.std.c
Article #15Re: What is the value of `(unsigned) -1' ??
From: Larry Jones
Date: Tue, 27 Oct 1992 15:44
Date: Tue, 27 Oct 1992 15:44
30 lines
1873 bytes
1873 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. You're misreading 3.2.1.2. The relevant section says: When a signed integer is converted to an unsigned integer with equal or greater size, if the value of the 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 unsigned number that can be represented in the type with smaller size. Note carefully the punctuation in the last sentence: "otherwise" qualifies the whole sentence, but the following "if" only qualifies the part up to the semicolon; the part after the semicolon applies to all conversions of negative values, not just those where the unsigned type has greater size. So, to answer your question, the value of "(unsigned) -1" is UINT_MAX. ---- Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH 45150-2789 513-576-2070 larry.jones@sdrc.com or ...uunet!sdrc!larry.jones I don't need to do a better job. I need better P.R. on the job I DO. -- Calvin
Technical Details
Message-ID:
<2171@sdrc.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!sdrc!thor!scjonesReferences:
<1992Oct27.071744.4871@netcom.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!sdrc!thor!scjones From: scjones@thor.sdrc.com (Larry Jones) Newsgroups: comp.std.c Subject: Re: What is the value of `(unsigned) -1' ?? Summary: UINT_MAX Message-ID: <2171@sdrc.COM> Date: 27 Oct 92 15:44:24 GMT References: <1992Oct27.071744.4871@netcom.com> Sender: news@sdrc.COM Lines: 30