tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: using the interfaces in ctype.h



> There are two cases one has to consider for use of isspace() etc.

> 1) if x is an int (wider than a char), and is the result of getc(),
> then x will be in the range [-1, UCHAR_MAX].

No; x will be in the range [0..UCHAR_MAX] or be EOF, which latter
happens to be -1 in our implementation but may be different.  (Unless
you were speaking from a strictly NetBSD perspective, rather than a
correct-use-of-ctype perspective.  Your mention of 1's-complement
machines makes me think not.)

> The phrase
>          .. if (isspace((unsigned char) buf[0])) ...
> won't work if isspace() is in-line and there's not enough casting in
> the macro.

I can't see how it could fail.  Could you give an example?

> I'm running 3.1, so I may have the wrong header files; but this would
> imply that (for example) isspace() should change from
>    ((int)((_ctype_ + 1)[(c)] & _S)
> to
>    ((int)((_ctype_ + 1)[(int)(c)] & _S)

I think this would be a very bad idea.  The existing code draws
warnings from some compiler versions about "array subscript has type
char", which let a coder catch such sloppy code; while this doesn't
apply to 3.1's compiler in my experience, doing it for 3.1 leads to the
idea of doing it for later versions, for which it *does* matter.

/~\ The ASCII                           der Mouse
\ / Ribbon Campaign
 X  Against HTML               mouse%rodents.montreal.qc.ca@localhost
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index