This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH/RFA] Distinguish between EOF and character with value 0xff
- From: Wizards' Guild <wizardsguild at earthlink dot net>
- To: newlib at sourceware dot org
- Cc: Eric Blake <ebb9 at byu dot net>
- Date: Fri, 24 Apr 2009 08:54:48 -0400 (GMT-04:00)
- Subject: Re: [PATCH/RFA] Distinguish between EOF and character with value 0xff
- Reply-to: Wizards' Guild <wizardsguild at earthlink dot net>
Eric,
It occurred to me that using __typeof__ causes another potential issue. If the user calls toupper((unsigned)c), the result ends up being unsigned, which could propagate through the surrounding code and cause warnings or unexpected results. In each of these three macros we should ensure the result is int, as the function would be. I would do it this way:
#define toupper(__c) __extension__ ({ __typeof__(__c) __x = (__c); islower(__x) ? (int) __x - 'a' + 'A' : (int) __x; })
Note that I have intentionally removed the inner parens in the ternary so that the cast is applied to __x prior to doing the arithmetic.
What do you think?
Seems like the `__ctype_ptr__ ==` test would add a lot of overhead; I'd rather see this remain a build-time test. On my primary architecture (nios2) it almost doubles the size of the call site to load the <WHAT> address.
Mike
---
Mike Burgess
Avanex Corporation
607-562-7169