isalpha.3: Note circumstances where 'c' must be cast to 'unsigned char'

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2016-11-17 21:51:05 +01:00
parent d81889735b
commit 3c5ba5ed1c
1 changed files with 32 additions and 0 deletions

View File

@ -312,6 +312,38 @@ and
.BR isascii_l ()
is a GNU extension.
.SH NOTES
The standards require that the argument
.I c
for these functions is either
.B EOF
or a value that is representable in the type
.IR "unsigned char" .
If the argument
.I c
is of type
.IR char ,
it must be cast to
.IR "unsigned char" ,
as in the following example:
.nf
.in +4n
char c;
\&...
res = toupper((unsigned char) c);
.in
.fi
This is necessary because
.I char
may be the equivalent
.IR "signed char" ,
in which case a byte where the top bit is set would be sign extended when
converting to
.IR int ,
yielding a value that is outside the range of
.IR "unsigned char" .
The details of what characters belong to which class depend on the
locale.
For example,