Return-Path: Delivered-To: apmail-stdcxx-dev-archive@www.apache.org Received: (qmail 76196 invoked from network); 2 Apr 2008 21:10:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Apr 2008 21:10:13 -0000 Received: (qmail 60523 invoked by uid 500); 2 Apr 2008 21:10:13 -0000 Delivered-To: apmail-stdcxx-dev-archive@stdcxx.apache.org Received: (qmail 60500 invoked by uid 500); 2 Apr 2008 21:10:13 -0000 Mailing-List: contact dev-help@stdcxx.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@stdcxx.apache.org Delivered-To: mailing list dev@stdcxx.apache.org Received: (qmail 60491 invoked by uid 99); 2 Apr 2008 21:10:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Apr 2008 14:10:12 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [208.30.140.160] (HELO moroha.roguewave.com) (208.30.140.160) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Apr 2008 21:09:23 +0000 Received: from exchmail01.Blue.Roguewave.Com (exchmail01.blue.roguewave.com [10.22.129.22]) by moroha.roguewave.com (8.13.6/8.13.6) with ESMTP id m32L9gQX024926 for ; Wed, 2 Apr 2008 21:09:42 GMT X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: [PATCH] STDCXX-423 LIMITS.cpp assumes integers with no padding bits Date: Wed, 2 Apr 2008 15:09:55 -0600 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH] STDCXX-423 LIMITS.cpp assumes integers with no padding bits Thread-Index: AciMbwhDpNMTXVUDS5+YWFQO5v98agIlknlQ References: <47E58C6D.6070204@roguewave.com> From: "Scott Zhong" To: X-Virus-Checked: Checked by ClamAV on apache.org > -----Original Message----- > From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor > Sent: Saturday, March 22, 2008 4:47 PM > To: dev@stdcxx.apache.org > Subject: Re: [PATCH] STDCXX-423 LIMITS.cpp assumes integers with no > padding bits >=20 > Sorry Scott, I'm still not sure this is completely correct. >=20 > According to 7.18.1.1 of C99, "The typedef name intN_t designates > a signed integer type with width N, no padding bits, and a two's > complement representation." >=20 > Can you point me to the part of the patch that checks that each > of the exact-width types has no padding bits and that it uses > a two's complement representation? >=20 > A few more comments are inline... >=20 > Scott Zhong wrote: > > Index: LIMITS.cpp > > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > --- LIMITS.cpp (revision 638996) > > +++ LIMITS.cpp (working copy) > > @@ -223,7 +223,19 @@ > > return bits; > > } > > > > +template > > +unsigned compute_type_bits() > > +{ > > + T max =3D T (one); > > + T current =3D T(one); > > + int bits =3D 1; > > > > + for (; T (current * 2) > max; current *=3D2, max *=3D 2, = bits++) { } > > + > > + return bits; > > +} >=20 > This function computes the number of bits in the value representation > of the type T. We also need to compute the number of bits in the object > representation of the type (i.e., sizeof(T) * CHAR_BIT). Only if the > two match, and when (no_twos_complement =3D=3D 0) holds can we define > the exact-width types. >=20 > > + > > + > > // used to compute the size of a pointer to a member function > > struct EmptyStruct { }; > > > > @@ -397,6 +409,12 @@ > > // 1 for a 16-bit integer, etc) > > int width_bits =3D 0; > > > > + // store exact bit size of each type > > + int ushort_bits =3D compute_type_bits (); > > + int uint_bits =3D compute_type_bits (); > > + int ulong_bits =3D compute_type_bits (); > > + int ullong_bits =3D compute_type_bits (); >=20 > The last line needs to be guarded in case long long is not > recognized as a type (e.g., EDG eccp in strict mode). >=20 > Martin >=20 Martin, the macro LLong already takes care of this.