Topic: Defect Report: 23.3.5.1p2
Author: Dag Henriksson <dag_henriksson@hotmail.com>
Date: Mon, 26 Jan 2004 16:00:53 +0000 (UTC) Raw View
[Note: Forwarded to C++ committee. -sdc ]
23.3.5.1 bitset constructors
bitset(unsigned long val);
2 Effects: Constructs an object of class bitset<N>, initializing the first M
bit positions to the corresponding
bit values in val. M is the smaller of N and the value CHAR_BIT * sizeof
(unsigned
long).249)
If M < N, remaining bit positions are initialized to zero.
*****************
Object-representation vs. value-representation strikes again. CHAR_BIT *
sizeof (unsigned long) does not give us the number of bits an unsigned long
uses to hold the value. Thus, the first M bit position above is not
guaranteed to have any corresponding bit values in val.
--
Dag Henriksson
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: gennaro_prota@yahoo.com (Gennaro Prota)
Date: Tue, 27 Jan 2004 04:15:49 +0000 (UTC) Raw View
On Mon, 26 Jan 2004 16:00:53 +0000 (UTC), Dag Henriksson
<dag_henriksson@hotmail.com> wrote:
>
>[Note: Forwarded to C++ committee. -sdc ]
>
>23.3.5.1 bitset constructors
>bitset(unsigned long val);
>2 Effects: Constructs an object of class bitset<N>, initializing the first M
>bit positions to the corresponding
>bit values in val. M is the smaller of N and the value CHAR_BIT * sizeof
>(unsigned
>long).249)
>If M < N, remaining bit positions are initialized to zero.
>*****************
>
>Object-representation vs. value-representation strikes again. CHAR_BIT *
>sizeof (unsigned long) does not give us the number of bits an unsigned long
>uses to hold the value. Thus, the first M bit position above is not
>guaranteed to have any corresponding bit values in val.
Indeed. I submitted a DR on this many months ago but it was rejected.
Well, just appending it here because there was also a proposed
(obvious) resolution :)
------
The description of
bitset(unsigned long val);
in the standard states (23.3.5.1 [lib.bitset.cons] paragraph 2):
Constructs an object of class bitset<N>, initializing the first
M bit positions to the corresponding bit values in val. M is the
smaller of N and the value CHAR_BIT * sizeof (unsigned long).249)
Since the standard doesn't prohibit an unsigned long to have unused
bits, CHAR_BIT * sizeof(unsigned long) should be replaced by
"the number of bits used by unsigned long to represent values"
Note 249 could be changed to:
"249) that's numerically equal to std::numeric_limits<unsigned
long>::digits
Genny.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]