Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2009-04-24 16:20:07 +0400
committerEric Blake <eblake@redhat.com>2009-04-24 16:20:07 +0400
commit1335bf3c5d217473acc6b3de664076d2397c58aa (patch)
tree8e490dde302e896e80a6078c056d73cbcd594163 /newlib/libc/include/ctype.h
parent5921804481c346f032a24c19fc294cc5690e0f3b (diff)
Trigger gcc warning if isFoo macros are called with plain char.
* libc/include/ctype.h (isalpha, isupper, islower, isdigit) (isxdigit, isspace, ispunct, isalnum, isprint, isgraph) (iscntrl, isblank, toupper, tolower): Rewrite to let 'gcc -Wall' warn when user calls macro with a char argument.
Diffstat (limited to 'newlib/libc/include/ctype.h')
-rw-r--r--newlib/libc/include/ctype.h34
1 files changed, 20 insertions, 14 deletions
diff --git a/newlib/libc/include/ctype.h b/newlib/libc/include/ctype.h
index c2e393b31..0e4a0d08d 100644
--- a/newlib/libc/include/ctype.h
+++ b/newlib/libc/include/ctype.h
@@ -45,22 +45,26 @@ _CONST
extern __IMPORT char *__ctype_ptr__;
#ifndef __cplusplus
-#define isalpha(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))
-#define isupper(c) (((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))==_U)
-#define islower(c) (((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))==_L)
-#define isdigit(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_N)
-#define isxdigit(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_X|_N))
-#define isspace(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_S)
-#define ispunct(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_P)
-#define isalnum(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L|_N))
-#define isprint(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_P|_U|_L|_N|_B))
-#define isgraph(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_P|_U|_L|_N))
-#define iscntrl(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_C)
+/* These macros are intentionally written in a manner that will trigger
+ a gcc -Wall warning if the user mistakenly passes a 'char' instead
+ of an int containing an 'unsigned char'. */
+#define isalpha(c) ((__ctype_ptr__+1)[c]&(_U|_L))
+#define isupper(c) (((__ctype_ptr__+1)[c]&(_U|_L))==_U)
+#define islower(c) (((__ctype_ptr__+1)[c]&(_U|_L))==_L)
+#define isdigit(c) ((__ctype_ptr__+1)[c]&_N)
+#define isxdigit(c) ((__ctype_ptr__+1)[c]&(_X|_N))
+#define isspace(c) ((__ctype_ptr__+1)[c]&_S)
+#define ispunct(c) ((__ctype_ptr__+1)[c]&_P)
+#define isalnum(c) ((__ctype_ptr__+1)[c]&(_U|_L|_N))
+#define isprint(c) ((__ctype_ptr__+1)[c]&(_P|_U|_L|_N|_B))
+#define isgraph(c) ((__ctype_ptr__+1)[c]&(_P|_U|_L|_N))
+#define iscntrl(c) ((__ctype_ptr__+1)[c]&_C)
#if defined(__GNUC__) && \
(!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
#define isblank(c) \
- __extension__ ({ int __c = (c); ((__ctype_ptr__)[(unsigned)((__c)+1)]&_B) || (__c) == '\t';})
+ __extension__ ({ __typeof__ (c) __c = (c); \
+ ((__ctype_ptr__+1)[__c]&_B) || (__c) == '\t';})
#endif
@@ -69,9 +73,11 @@ extern __IMPORT char *__ctype_ptr__;
disabled if the system supports the extended character sets. */
# if defined(__GNUC__) && !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
# define toupper(c) \
- __extension__ ({ int __x = (c); islower(__x) ? (__x - 'a' + 'A') : __x;})
+ __extension__ ({ __typeof__ (c) __x = (c); \
+ islower(__x) ? (__x - 'a' + 'A') : __x;})
# define tolower(c) \
- __extension__ ({ int __x = (c); isupper(__x) ? (__x - 'A' + 'a') : __x;})
+ __extension__ ({ __typeof__ (c) __x = (c); \
+ isupper(__x) ? (__x - 'A' + 'a') : __x;})
#endif
#endif /* !__cplusplus */