NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

standards/46276: CHAR_MAX/CHAR_MIN don't change with -funsigned-char

>Number:         46276
>Category:       standards
>Synopsis:       CHAR_MAX/CHAR_MIN don't change with -funsigned-char
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    standards-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 28 18:25:00 +0000 2012
>Originator:     David A. Holland
>Release:        current (20120328)
Machine: amd64

Section paragraph 2 of C99 says:

If the value of an object of type char is treated as a signed integer
when used in an expression, the value of CHAR_MIN shall be the same as
that of SCHAR_MIN and the value of CHAR_MAX shall be the same as that
of SCHAR_MAX. Otherwise, the value of CHAR_MIN shall be 0 and the
value of CHAR_MAX shall be the same as that of UCHAR_MAX.

which we do, but only for the per-platform static default of whether
char is unsigned. It seems to me that these ought to flip if
-funsigned-char or similar is used to pick the opposite signedness
from the platform default.


code reading.


Move the definitions of CHAR_MIN/CHAR_MAX out of MD limits.h and use
something gcc-provided to pick the signed or unsigned values. If gcc
doesn't provide a way to check at runtime, I guess we need to add one.

I'm not clear on whether this:

#if ('7' - '8') < 0
#define CHAR_MIN 0

will work. Although character constants are allowed in cpp
expressions, and '7' is guaranteed to be less than '8', there are
integer promotions to consider; I'm not convinced offhand that the
behavior is clearly defined for cpp expressions, and even if it is,
it's not altogether likely to be implemented correctly in all

Home | Main Index | Thread Index | Old Index