'\xff' is an int ... apparently.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PaulBlay
    Knight
    • Jan 2009
    • 657

    '\xff' is an int ... apparently.

    The mouseclick command from the initialization of cmd_hidden (see below) provokes the warning "warning C4245: 'initializing' : conversion from 'int' to 'unsigned char', signed/unsigned mismatch". (VC++ on level 4).

    Code:
     { "Mouse click",          '\xff', do_cmd_mouseclick }
    Unless I'm mistaken \xff is 255 which is the last of the unsigned char range, so I don't know why VC++ thinks it is an int...
    Currently turning (Angband) Japanese.
  • ajps
    Apprentice
    • May 2007
    • 50

    #2
    Originally posted by PaulBlay
    Unless I'm mistaken \xff is 255 which is the last of the unsigned char range, so I don't know why VC++ thinks it is an int...
    Technically is an int, in that all character constants are of integer type, not char type, regardless of their value. Still seems a strange thing to complain about though.

    Comment

    • PaulBlay
      Knight
      • Jan 2009
      • 657

      #3
      Originally posted by ajps
      Technically is an int, in that all character constants are of integer type, not char type, regardless of their value. Still seems a strange thing to complain about though.
      The strange thing with that is that all the other character constants were fine with VC++. Maybe it's only the \x style it doesn't like?
      Currently turning (Angband) Japanese.

      Comment

      • Pete Mack
        Prophet
        • Apr 2007
        • 6883

        #4
        It doesn't look like an int to me... You can do a reinterpret cast, if you care about the warning:
        Code:
        (unsigned char) '\xff'

        EDIT: I see why it's making the warning. It detects that '\xff', of type char, is out of range of MAX_CHAR ('\0x7f'), so the cast from signed to unsigned might be improper. The warning is a little opaque.

        Comment

        • zaimoni
          Knight
          • Apr 2007
          • 590

          #5
          Originally posted by PaulBlay
          The mouseclick command from the initialization of cmd_hidden (see below) provokes the warning "warning C4245: 'initializing' : conversion from 'int' to 'unsigned char', signed/unsigned mismatch". (VC++ on level 4).

          Code:
           { "Mouse click",          '\xff', do_cmd_mouseclick }
          Unless I'm mistaken \xff is 255 which is the last of the unsigned char range, so I don't know why VC++ thinks it is an int...
          While '\xff' is a character literal with bitpattern FF (in hex), that does promote to int, its value is only 255 on targets where char is unsigned.

          The warning is harmless on the usual two's complement machines.

          What I don't get is why MSVC is messing with the promotion at all.
          Zaiband: end the "I shouldn't have survived that" experience. V3.0.6 fork on Hg.
          Zaiband 3.0.10 ETA Mar. 7 2011 (Yes, schedule slipped. Latest testing indicates not enough assert() calls to allow release.)
          Z.C++: pre-alpha C/C++ compiler system (usable preprocessor). Also on Hg. Z.C++ 0.0.10 ETA December 31 2011

          Comment

          Working...
          😀
          😂
          🥰
          😘
          🤢
          😎
          😞
          😡
          👍
          👎