Harald van Dijk said:
So _you_ don't actually have any example of a system where 'A'..'F' are
not sequential? Would you drop the attitude, then? It's not required by
the standard, but if it's true that no conforming implementation of C has
ever yet been produced where 'A'..'F' are not sequential, then it's more
likely that some future C standard will guarantee it, than that someone
produces a system where other characters exist between 'A'..'F'.
I'd be happy with that option too (a guarantee that they be
consecutive and increasing). Writing either the string lookup or the
switch statement solution always seems daft when I know the
subtraction would have worked on all machines I've ever used[1].
However, something in me balks at making an assumption not guaranteed
by the language.
Is it worth asking for 'int toxvalue(int c)', or a guarantee that 'a' to
'f' and 'A' to 'F' are consecutive? It seems a small matter, but an
irritating one.
[1] The oddest being a CDC with a 6-bit character code, OK, you can't
implement C in a conforming way on such a machine, but even that had
consecutive A-F (no lowercase).