Boost logo

Boost :

From: Noah Stein (noah_at_[hidden])
Date: 2002-04-16 16:25:02


> -----Original Message-----
> From: boost-admin_at_[hidden] [mailto:boost-admin_at_[hidden]]On
> Behalf Of James S. Adelman
> Sent: Tuesday, April 16, 2002 12:12 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] Re: Re: Adding Loki to Boost (reprise)

> > Yes, and to add to this tangent, 3.9.1p1 states "Plain char,
> signed char,
> > and unsigned char are three distinct types." Strangely, 3.9p2
> talks about
> > how "... the underlying bytes making up the object can be copied into an
> > array of char or unsigned char. If the content of the array of char or
> > unsigned char is copied back into the object, the object shall
> subsequently
> > hold its original value." I guess there's no requirement that
> this copying
> > work properly with signed chars! :)
>
> Do you mean with signed chars as the source, or as the
> destination? If you
> mean as source, this will work, as specified. This does not
> negate the fact
> that they are different types, just as struct A { int a;}; and
> struct B {int
> a;}; are different types. If you mean as destination, this could be
> impossible, as signed char could have fewer distinct values than unsigned
> char, for example, with sign-magnitude representation. Then
> unsigned char
> a=2<<(CHAR_BIT-1); signed char b[1]; b[0]=a; if(b[0]==0) {a=3;}
> a=b[0]; might
> alter the value of a.
>

There's no deep issue or defect I was trying to uncover or understand.
Initially I just wanted to point out how, although "signed int" means "int",
"signed char" doesn't mean char even if the compiler chooses to represent
characters as a signed quantity. It seemed inconsistent, so it was a nice
addition to the discussion at hand.

While I was looking for the reference to that in the standard, I came across
the second topic about chars and unsigned chars. I thought it strange that
the standard should specifically mention that objects can be copied as an
array of chars and unsigned chars, but didn't mention that they could also
be unsigned chars. It seemed weird since 3.9.1p1 also states that "A char,
a signed char, and an unsigned char occupy the same amount of storage and
have the same alignment requirements." I just wonder why the standard takes
the effort to state "char and unsigned char" in 3.9p2. Does anyone know if
signed chars were specifically excluded for a reaoson from 3.9p2, and if so,
why?

-- Noah


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk