delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/12/12/17:44:49

Message-ID: <000901c0647e$8331a6a0$5fdc883e@oemcomputer>
From: "Stephen Silver" <djgpp AT argentum DOT freeserve DOT co DOT uk>
To: <djgpp-workers AT delorie DOT com>
Subject: ctype.h in C++
Date: Tue, 12 Dec 2000 21:00:06 -0000
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Reply-To: djgpp-workers AT delorie DOT com

There is a problem with the ctype.h header when used in C++: all 13
standard functions are defined as macros, which is permissible in C, but
not in C++.  In particular, the compiler chokes on expressions such as
std::tolower('A') because a namespace qualifier cannot be applied to a
macro.

In order to fix this problem without forcing the use of the non-inline
versions of the functions, I've patched include\inline\ctype.ha to
define all the functions as inline functions rather than macros (when
__cplusplus is defined).  I've appended the patch below.

Stephen Silver


*** ctype.ha.old Sun Jun 28 18:06:22 1998
--- ctype.ha Tue Dec 12 15:32:36 2000
***************
*** 18,21 ****
--- 18,91 ----
  extern unsigned char __dj_ctype_tolower[];
  
+ #ifdef __cplusplus
+ 
+ inline int
+ isalnum(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISALNUM;
+ }
+ inline int
+ isalpha(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISALPHA;
+ }
+ inline int
+ iscntrl(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISCNTRL;
+ }
+ inline int
+ isdigit(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISDIGIT;
+ }
+ inline int
+ isgraph(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISGRAPH;
+ }
+ inline int
+ islower(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISLOWER;
+ }
+ inline int
+ isprint(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISPRINT;
+ }
+ inline int
+ ispunct(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISPUNCT;
+ }
+ inline int
+ isspace(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISSPACE;
+ }
+ inline int
+ isupper(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISUPPER;
+ }
+ inline int
+ isxdigit(int c)
+ {
+   return __dj_ctype_flags[c+1] & __dj_ISXDIGIT;
+ }
+ inline int
+ tolower(int c)
+ {
+   return __dj_ctype_tolower[c+1];
+ }
+ inline int
+ toupper(int c)
+ {
+   return __dj_ctype_toupper[c+1];
+ }
+ 
+ #else
+ 
  #define isalnum(c) (__dj_ctype_flags[(int)(c)+1] & __dj_ISALNUM)
  #define isalpha(c) (__dj_ctype_flags[(int)(c)+1] & __dj_ISALPHA)
***************
*** 33,35 ****
--- 103,107 ----
  #define toupper(c) (__dj_ctype_toupper[(int)(c)+1])
  
+ #endif /* __cplusplus */
+ 
  #endif /* __dj_include_inline_ctype_hi_ */

- Raw text -


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