some unusual errors
J. J. Farrell
Wed Sep 23 23:42:00 GMT 1998
> From: Michael Richardson <firstname.lastname@example.org>
> >>>>> "DJ" == DJ Delorie <email@example.com> writes:
> DJ> 3. Remember that getchar() returns in int - for the very same reason,
> DJ> so that EOF is not in the range of valid characters. getchar()
> DJ> returns EOF or 0..255, which is NOT the same range as the range for
> DJ> type `signed char'.
> DJ> Basically, if you're a programmer and you've stumbled onto this
> DJ> problem, you have a problem with your code.
> I think the problem is posix saying that is* needs to process EOF
> without deciding if "char" is signed or not.
It's nothing to do with POSIX - it's the C Standard. The ctype functions
are defined the way they are so they are guaranteed to work on everything
which getchar() and friends return, but are also practical to implement
as macros for speed of execution.
> isspace(foo) has been around for a *LONG* time. It shouldn't break.
It certainly has, but then the C Standard has been around for almost 10
years, and I don't think the definition of isspace() was changed from
how it was before the Standard. It isn't breaking anyway - it's just
the compiler giving you a spurious warning message. If it's not working
that's probably down to a bug in your code which would show up on any
compiler which treats plain chars as signed.
> I will fix my code to use unsigned char's, fine, but I suggest that gnu-win32
> make char unsigned by default then.
There's no reason why it should; there have been implementations from
the early days which had it as signed and others which had it as
unsigned. That's why the Standard explicitly doesn't specify whether
it is signed or unsigned.
You'd be far better off writing your C to be as portable as possible
rather than expecting compilers to behave in a certain way when they're
not obliged to. If you're porting a chunk of code which assumes that
a plain char is unsigned, the best long term fix is to get rid of those
assumptions; but in the short term, I think there's an option to gcc
to make it treat plain chars as unsigned.
For help on using this list (especially unsubscribing), send a message to
"firstname.lastname@example.org" with one line of text: "help".
More information about the Cygwin