Thread (9 messages) 9 messages, 5 authors, 2016-06-15

Re: Usage of isspace and friends

From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-06-15 22:42:08


On Wed, 12 Oct 2005, Junio C Hamano wrote:
Huh?  isspace is "int isspace(int)".  Presumably standard
integral promotion rules applies here whether char is signed or
unsigned, doesn't it?
No.

The input range for the "isxxxxx()" macros is the same as the range for 
the "[f]getc[h]()" family: unsigned char + EOF (the latter usually being 
-1).

So Morten is right - if you have a "char *", it should not be dereferenced 
and used directly, although I think glibc does the right thing (and, in 
fact, I can't understand why the standards haven't been updated to do the 
right thing: it's _not_ that hard. In fact, it should be trivial apart 
from the special case of "255" that looks undistinguishable from EOF in 
signed char representation).

I'm almost goign to suggest that we do our own ctype.h, just to get the 
sane semantics: we want locale-independence, _and_ we want the right 
signed behaviour. Plus we only use a very small subset of ctype.h anyway 
(isspace, isalpha, isdigit and isalnum).

			Linus
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help