From: jjf AT bcs DOT org DOT uk (J. J. Farrell) Subject: Re: some unusual errors 24 Sep 1998 09:25:27 -0700 Message-ID: <199809232135.OAA04878.cygnus.gnu-win32@aleph.ssd.hal.com> References: <199809222030 DOT QAA25521 AT venus DOT solidum DOT com> Content-Type: text To: mcr AT solidum DOT com (Michael Richardson) Cc: dj AT delorie DOT com, gnu-win32 AT cygnus DOT com > From: Michael Richardson > > > >>>>> "DJ" == DJ Delorie 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[3]) 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 "gnu-win32-request AT cygnus DOT com" with one line of text: "help".