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)
>Organization:
>Environment:
n/a
Machine: amd64
>Description:

Section 5.2.4.2.1 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.

>How-To-Repeat:

code reading.

>Fix:

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 SCHAR_MIN
#define CHAR_MAX SCHAR_MAX
#else
#define CHAR_MIN 0
#define CHAR_MAX UCHAR_MAX
#endif

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
compilers.



Home | Main Index | Thread Index | Old Index