delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/02/10/03:16:40

Sender: vheyndri AT rug DOT ac DOT be
Message-Id: <34E00C85.57DE@rug.ac.be>
Date: Tue, 10 Feb 1998 09:15:01 +0100
From: Vik Heyndrickx <Vik DOT Heyndrickx AT rug DOT ac DOT be>
Mime-Version: 1.0
To: DJ Delorie <dj AT delorie DOT com>
Cc: djgpp-workers AT delorie DOT com
Subject: Re: char != unsigned char... sometimes, sigh
References: <199802092259 DOT RAA14332 AT delorie DOT com>

The following is an ANSI compliant behaving macro, and it supports also
'signed char'
It yields reasonably efficient hard-code.

#define isupper(c) ({int t=(c);unsigned v;\
                     ++t;\
                     if(t<0)t+=256;\
                     v=__dj_ctype_flags[t];\
                     (v&__dj_ISUPPER)!=0;})

The following is an ANSI compliant behaving macro, it supports only
'unsigned char'.
It yields the most efficient hard-code possible in many cases.

#define isupper(c) ({int t=(c);unsigned v;\
                     ++t;\
                     v=__dj_ctype_flags[t];\
                     (v&__dj_ISUPPER)!=0;})

Note that ANY change you will make to these macro's will turn them less
efficient. I know where I am talking about.

Note that if the first macro I propose is used on an 'unsigned char',
the test whether the value is negative is optimized out by the compiler.
The function version could not have this feature of course.

-- 
 \ Vik /-_-_-_-_-_-_/   
  \___/ Heyndrickx /          
   \ /-_-_-_-_-_-_/

- Raw text -


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