delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/02/04/00:36:48

Sender: bill AT taniwha DOT tssc DOT co DOT nz
Message-ID: <34D7FD21.36B4842A@taniwha.tssc.co.nz>
Date: Wed, 04 Feb 1998 18:31:14 +1300
From: Bill Currie <bill AT taniwha DOT tssc DOT co DOT nz>
MIME-Version: 1.0
To: Vik Heyndrickx <Vik DOT Heyndrickx AT rug DOT ac DOT be>
CC: DJ Delorie <dj AT delorie DOT com>, eliz AT is DOT elta DOT co DOT il, djgpp-workers AT delorie DOT com
Subject: Re: char != unsigned char... sometimes, sigh
References: <199802031335 DOT IAA27878 AT delorie DOT com> <34D72299 DOT 3037 AT rug DOT ac DOT be>

IMHO, this discussion is both too long and pointless.  Even though they
tend to be implemented as macros, the is* functions DO have the
following prototypes (Linux man patge for isupper):

       int isalnum (int c);
       int isalpha (int c);
       int isascii (int c);
       int isblank (int c);
       int iscntrl (int c);
       int isdigit (int c);
       int isgraph (int c);
       int islower (int c);
       int isprint (int c);
       int ispunct (int c);
       int isspace (int c);
       int isupper (int c);
       int isxdigit (int c);

Even if these functions were implemented as functions rather than
macros, it wouldn't one bit of difference, passing a char (signed,
unsigned or ambiguous) would ALWAYS cause `unexpected' results, the
compiler will always do something funny when it extends the bits.

Basicly, anybody uses a char between fgetc and is* /DESERVES/ to have
their program break, seeing as how fgetc is declared as:

       int fgetc(FILE *stream);

which is guaranteed to return a value between -1 and 255 (assuming
EOF==-1).

       char c; /* or signed char or unsigned char */
       c=fgetc(file);
       if (isupper(c)) {}

Will, no matter what, give undefined results for EOF, but

       int c;
       c=fgetc(file);
       if (isupper(c)) {}

is guaranteed to work.

So really, the djgpp ctype.h header file should just make sure c is in
the right range (don't want array bounds checking to fail) and be done
with it. Forget about coping with `char's of any flavour, they're
irrellevant.

If anybody disagrees with this, please tell me why.

Bill
-- 
Leave others their otherness.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019