Why would the character 'A' be compared with 0x41?


SUBMITTED BY: menamagice

DATE: Aug. 9, 2017, 2:08 a.m.

FORMAT: Text only

SIZE: 408 Bytes

HITS: 208

  1. I was looking at some C++ code and found the following construct:
  2. if('A' == 0x41) {
  3. // ...
  4. } else if('A' == 0xc1) {
  5. // ...
  6. } else {
  7. // ...
  8. }
  9. I get a Visual Studio warning saying:
  10. Warning C4127 conditional expression is constant.
  11. Visual Studio is clearly right - surely 'A' is defined to be 0x41. Why is the author writing this code, given that two out of the three branches are dead code?

comments powered by Disqus