Topic: 0'..'9' are contiguous... where does C++98 say so?


Author: James Dennett <jdennett@acm.org>
Date: Tue, 10 Apr 2001 04:08:44 GMT
Raw View
I've long been of the belief that the characters '0' to '9'
are guaranteed to be in order and contiguous, so that for
a digit d in '0'..'9', d-'0' must give the integral value
of that digit.

C99 states this explicitly, but I cannot find a clear
statement in C++98.  The closest thing I can find in C++98
is 21.2.1.1.2/13, but that's (a) unclear, and (b) not
obviously strong enough.

The Standard makes various references to the "range"
'0'..'9', but I cannot find the text which guarantees
that '0','1','2','3','4','5','6','7','8',9' is a
range.

Can anybody point me to a clear statement in 14882:1998
that the digits "do the right thing" at runtime?  It's a
largely academic question, but I'm disturbed that I can't
find a clear guarantee.

-- James Dennett <jdennett@acm.org>

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: "William M. Miller" <wmmiller@MailAndNews.com>
Date: Wed, 11 Apr 2001 15:47:26 GMT
Raw View
>===== Original Message From James Dennett <jdennett@acm.org> =====
>I've long been of the belief that the characters '0' to '9'
>are guaranteed to be in order and contiguous, so that for
>a digit d in '0'..'9', d-'0' must give the integral value
>of that digit.
>
>C99 states this explicitly, but I cannot find a clear
>statement in C++98.  The closest thing I can find in C++98
>is 21.2.1.1.2/13, but that's (a) unclear, and (b) not
>obviously strong enough.
>
>The Standard makes various references to the "range"
>'0'..'9', but I cannot find the text which guarantees
>that '0','1','2','3','4','5','6','7','8',9' is a
>range.
>
>Can anybody point me to a clear statement in 14882:1998
>that the digits "do the right thing" at runtime?  It's a
>largely academic question, but I'm disturbed that I can't
>find a clear guarantee.

The Committee also found it disturbing, to the extent that it
was clasified as a defect to be fixed in the Technical
Corrigendum.  See
http://www.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#173.

-- William M. Miller

---
[ 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.research.att.com/~austern/csc/faq.html                ]