git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Usage of isspace and friends

From
Linus Torvalds <torvalds@osdl.org>
Date
Oct 13, 2005, 15:04 UTC
Message-ID
<Pine.LNX.4.64.0510130756550.15297@g5.osdl.org>
In-Reply-To
<7vachd6hdx.fsf@assigned-by-dhcp.cox.net>
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
Previous: Junio C HamanoNext: H. Peter Anvin
Message 6 of 10 in “Usage of isspace and friends”
  1. Morten WelinderOct 12, 2005
  2. Junio C HamanoOct 13, 2005
  3. Antti-Juhani KaijanahoOct 13, 2005
  4. H. Peter AnvinOct 13, 2005
  5. Junio C HamanoOct 13, 2005
  6. Linus TorvaldsOct 13, 2005
  7. H. Peter AnvinOct 13, 2005
  8. Linus TorvaldsOct 13, 2005
  9. H. Peter AnvinOct 13, 2005
  10. Linus TorvaldsOct 13, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.