[PATCH/RFA] Distinguish between EOF and character with value 0xff

Wizards' Guild wizardsguild@earthlink.net
Fri Apr 24 13:23:00 GMT 2009


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



More information about the Newlib mailing list