This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]