Mail Archives: djgpp-workers/2000/12/12/17:44:49
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 -