This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: 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


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