This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: avoid warnings on array[CHAR_CONSTANT]
- From: Eddie Kohler <kohler at icir dot org>
- To: Richard Henderson <rth at redhat dot com>
- Cc: Mike Stump <mrs at apple dot com>, gcc-patches at gcc dot gnu dot org, Jonathan Lennox <lennox at cs dot columbia dot edu>
- Date: Wed, 11 Jun 2003 16:46:54 -0700
- Subject: Re: PATCH: avoid warnings on array[CHAR_CONSTANT]
> > GCC doesn't warn on "c >= 'A' && c <= 'Z'"; it could, and that
> > code is almost always wrong under EBCDIC, but...
>
> No, that's correct under EBCDIC too.
The range "c >= 'A' && c <= 'Z'" includes non-alphabetic characters in
EBCDIC, which ASCII programmers almost certainly did not expect. Warning on
such inequalities would catch many programs that fail under EBCDIC, and few
programs that work correctly.
- Real programs use "a['A']" to set up character tables. Obviously I've
written such programs; I've seen the idiom elsewhere.
- The idiom compiles without warning under C.
- It's part of the C subset of C++.
- Its risks are no different under C than under C++.
- The revised warning still catches more likely mistakes than C's does.
- The alternatives are ugly:
"a[ (unsigned char)'A' ]"
(or, God forbid, "a[ static_cast<unsigned char>('A') ]")
"a[ (uint8_t)'A' ]"
or worse, incorrect:
"a[ (int)'A' ] /* ASCII-centric programmer! */"
Eddie