On Mon, 26 Jan 2004 15:24:56 +1100, "Peter Nilsson"
<ai***@acay.com .au> wrote in comp.lang.c:
"Jack Klein" <ja*******@spam cop.net> wrote in message
news:e2******** *************** *********@4ax.c om... On Mon, 26 Jan 2004 11:41:28 +1100, "Peter Nilsson"
<ai***@acay.com .au> wrote in comp.lang.c:
"pete" <pf*****@mindsp ring.com> wrote in message
news:40******** ***@mindspring. com...
> I wrote a version of itoa yesterday.
>
> Features: <snip> > 2 No object is assumed capable of representing the
> magnitude of INT_MIN.
But you do assume that the magnitude of INT_MIN+1 (and others) _are_
representable within an int. James Kuyper has argued in csc that this
need not be true in C99.
INT_MIN + 1 is certainly representable in a signed int. So is
-(INT_MIN + 1). Either you have misunderstood James' arguments, or he
is just plain wrong.
Well I guess you choose the latter. Here's one thread in which he discusses
this...
http://groups.google.com/groups?thre...2%40wizard.net
<snip> 6.6.2 makes this all quite clear.
ITYM 6.2.6, but see the link above.
Yes, I've seen the thread, and it is hair-splitting nonsense.
Paragraph 5 of 6.2.6.1:
<quote>
Certain object representations need not represent a value of the
object type. If the stored value of an object has such a
representation and is read by an lvalue expression that does
not have character type, the behavior is undefined. If such a
representation is produced by a side effect that modifies all or any
part of the object by an lvalue expression that does not have
character type, the behavior is undefined. Such a representation is
called a trap representation.
<unquote>
The contents of an object referenced by an lvalue of a particular type
(other than unsigned char) can be one of two things: a value or a
trap representation. It can't be both, it can't be neither.
Then there are paragraphs 1 & 2 of 6.2.6.2:
<quote>
1 For unsigned integer types other than unsigned char, the bits of the
object representation shall be divided into two groups: value bits and
padding bits (there need not be any of the latter). If there are N
value bits, each bit shall represent a different power of 2 between 1
and 2N-1, so that objects of that type shall be capable of
representing values from 0 to 2N - 1 using a pure binary
representation; this shall be known as the value representation. The
values of any padding bits are unspecified.
2 For signed integer types, the bits of the object representation
shall be divided into three groups: value bits, padding bits, and the
sign bit. There need not be any padding bits; there shall be exactly
one sign bit. Each bit that is a value bit shall have the same value
as the same bit in the object representation of the corresponding
unsigned type (if there are M value bits in the signed type and N in
the unsigned type, then M <= N). If the sign bit
is zero, it shall not affect the resulting value. If the sign bit is
one, the value shall be modified in one of the following ways:
— the corresponding value with sign bit 0 is negated (sign and
magnitude);
— the sign bit has the value -(2N) (two’s complement);
— the sign bit has the value -(2N - 1) (one’s complement).
Which of these applies is implementation-defined, as is whether the
value with sign bit 1 and all value bits zero (for the first two), or
with sign bit and all value bits 1 (for one’s complement), is a trap
representation or a normal value. In the case of sign and magnitude
and one’s complement, if this representation is a normal value it is
called a negative zero.
<unquote>
Each value bit contributes to a value, and the sign bit, when set
specifically has a value that combines with the value of the value
bits.
When the standard provides a list of anything, in this case possible
combinations of sign and value bits that may be trap representations ,
without a qualifier like "includes", that list is exclusive. Nowhere
in the standard does it say that any other combinations of sign and
value bits may be trap representations and not values.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html