This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch to use more safe-ctype macros
> > hex_digit_value (c)
> > unsigned int c;
> > {
> > + if (ISDIGIT (c))
> > + return c - '0';
> > if (c >= 'a' && c <= 'f')
> > return c - 'a' + 10;
> > if (c >= 'A' && c <= 'F')
> > return c - 'A' + 10;
> > - if (c >= '0' && c <= '9')
> > - return c - '0';
> > abort ();
>
> I would prefer if you left this one alone; I think it's more readable
> to have all three conditions take the same general form.
Libiberty exports a table for that purpose. This is what's in
libiberty.h, although nobody in gcc uses it (or calls hex_init) yet.
/* hex character manipulation routines */
#define _hex_array_size 256
#define _hex_bad 99
extern char _hex_value[_hex_array_size];
extern void hex_init PARAMS ((void));
#define hex_p(c) (hex_value (c) != _hex_bad)
/* If you change this, note well: Some code relies on side effects in
the argument being performed exactly once. */
#define hex_value(c) (_hex_value[(unsigned char) (c)])