Re: isodigit



Wojtek Lerch wrote:
I think the unsigned cast cakes care of it, as long as EOF is indeed
distinct from all the digits; but is that really guaranteed?
...
But if char is unsigned, it could be the same width as int, couldn't it?

Yes, but even so, the basic characters aren't allowed to have
negative values. That is independent of the signedness of
type "char"; an implementation can't claim conformance to
that requirement merely because its type "char" is unsigned.

If CHAR_MAX > INT_MAX, not all char values can be safely converted to int.
Does the standard guarantee that all the characters in the basic character
set can? (If not, what is the value of '9' when the char representing the
digit 9 is greater than INT_MAX?)

Certainly that was the intent. You could argue that otherwise,
the problematic basic characters would have negative values,
which is not allowed (as you observed). Further, the general
belief among the committee members during technical discussion
seemed to be that this requirement held for the basic character
value represented in type "char" no matter how wide "int" may
be, and hence, on an 8-bit-char EBCDIC host type "char" *must*
be unsigned (since the code for '0' is 0xC0, not 0xFFFFFFC0).
I think this might be deducible by combining 6.2.5p3 with
6.4.4.4p10.

In some locale where the set of digits includes non-basic
characters, testing for digitness might be a problem using
the macro under discussion, if one of the extra digits had the
same value as EOF when cast to (unsigned). However, that
macro clearly can't be used if locale-dependent digits are
what you want to test. (I would think that "octal digits"
are 0..7 and nothing else, in all locales.)
.



Relevant Pages

  • Re: How to add thousand separators
    ... First, this code is obsolete as written, because char is a dead data type and should not ... Note that both of these should be stored as string resources since they might need to be ... 18 digits for any reason. ... you have made a VERY SERIOUS DESIGN ERROR. ...
    (microsoft.public.vc.mfc)
  • Re: Naive implementation of strverscmp(3)
    ... It saves a call to strcspnif s1 has no digits, ... strverscmp(const char *s1, const char *s2); ... else if (t1-s1> t2-s2) ...
    (freebsd-hackers)
  • Naive implementation of strverscmp(3)
    ... strverscmp(const char *s1, const char *s2); ... p1 = strcspn(s1, digits); ...
    (freebsd-hackers)
  • Re: isodigit
    ... distinct from all the digits; ... But if char is unsigned, it could be the same width as int, couldn't it? ... Does the standard guarantee that all the characters in the basic character ...
    (comp.std.c)
  • Re: computers + floating-point = a chore
    ... simply because it's more convenient to display it ... You can see from this session that 15 digits of precision is not ... char buf; ... e = buf + strlen; ...
    (comp.lang.ruby)

Loading