Why do ctype functions accept int but want unsigned char / EOF?

I am using gcc (Ubuntu / Linaro 4.6.1-9ubuntu3) 4.6.1

The man page isalnum()says:

SYNOPSIS
       #include <ctype.h>

       int isalnum(int c);

However, he also says:

These functions check to see if c, which should be unsigned char or EOF, ...

I found that it isalnum()explodes for very large positive (or negative) values int(but it handles all the values short int).

Whether the manual page in which the int is passed should matter unsigned char, because the authors of C-libraries reserve the right to implement isalnum()in such a way as not to process all the values intwithout bloating

+6
1

C ...

/ 9899: 1999 ( ) :

§7.4

, . int, unsigned char EOF. , undefined.

( .) C89, C11 .

1 - :

int _CtypeBits[257] = { ... };

#define isalpha(c)  (_Ctype_bits[(c)+1]&_ALPHA);

c , unsigned char ( 8 , EOF - -1, ), . , , . , (, , , , ).

+6

Source: https://habr.com/ru/post/1661559/


All Articles