Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Which statements are correct?

Which statements are correct?

Scheduled Pinned Locked Moved C / C++ / MFC
c++debuggingquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ComplexLifeForm
    wrote on last edited by
    #1

    Hi, I have an old ANSI VC++ dialog based application which I would like to make it UNICODE enabled application. So I started converting all "char" types to "TCHAR" types. Howerever there is a certain piece of code that is sort of hardwired with statements like const char cEscape = -16; If I convert it to TCHAR equivalent and compile and execute const TCHAR cEscape = (const TCHAR)-16; the value of the cEscape variable (as seen in quickwatch window in VC++ debugger) is 65520 I am wondering should the value of the cEscape variable be 240 which is unsinged char equivalent of signed char -16 or the value 65520 is correct? Can someone please clarify? Thanks and Regards :)

    M M 2 Replies Last reply
    0
    • C ComplexLifeForm

      Hi, I have an old ANSI VC++ dialog based application which I would like to make it UNICODE enabled application. So I started converting all "char" types to "TCHAR" types. Howerever there is a certain piece of code that is sort of hardwired with statements like const char cEscape = -16; If I convert it to TCHAR equivalent and compile and execute const TCHAR cEscape = (const TCHAR)-16; the value of the cEscape variable (as seen in quickwatch window in VC++ debugger) is 65520 I am wondering should the value of the cEscape variable be 240 which is unsinged char equivalent of signed char -16 or the value 65520 is correct? Can someone please clarify? Thanks and Regards :)

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      How about const TCHAR cEscape = _T('\xF0'); That keeps the value -16 (240 unsigned) and it's generic/portable. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      C 1 Reply Last reply
      0
      • M Mark Salsbery

        How about const TCHAR cEscape = _T('\xF0'); That keeps the value -16 (240 unsigned) and it's generic/portable. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        C Offline
        C Offline
        ComplexLifeForm
        wrote on last edited by
        #3

        Thanks though I think my question is still unanswered. If the value of cEscape should be 240 (_T('\xF0') then could there be a reason that the VC++ 2005 compiler is evaluting it to 65520 and not 240 ! I have checked the disassembly and it shows that the compiler is assigning 0xFFF0 to the cEscape variable and not 0x00F0. Regards.

        M 1 Reply Last reply
        0
        • C ComplexLifeForm

          Thanks though I think my question is still unanswered. If the value of cEscape should be 240 (_T('\xF0') then could there be a reason that the VC++ 2005 compiler is evaluting it to 65520 and not 240 ! I have checked the disassembly and it shows that the compiler is assigning 0xFFF0 to the cEscape variable and not 0x00F0. Regards.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          psychedelic_fur wrote:

          could there be a reason that the VC++ 2005 compiler is evaluting it to 65520 and not 240

          Yes. I tested this (note I'm using VC++ 2005 SP2 compiler):     const TCHAR cEscape = _T('\xF0');     TCHAR s[10];     s[0] = cEscape; My compiler settings have "Treat wchar_t as Built-in Type" set to "Yes". cEscape is 240 as expected. If that setting isn't enabled, then the result may be different. If wchar_t is treated as a signed short int then the the entire value gets treated as negative.  Not good.  I suppose you can try this (preferred):    const TCHAR cEscape = _T('\x00F0'); or mask off the high byte (lame but works)    const TCHAR cEscape = _T('\xF0') & 0x00FF; Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          1 Reply Last reply
          0
          • C ComplexLifeForm

            Hi, I have an old ANSI VC++ dialog based application which I would like to make it UNICODE enabled application. So I started converting all "char" types to "TCHAR" types. Howerever there is a certain piece of code that is sort of hardwired with statements like const char cEscape = -16; If I convert it to TCHAR equivalent and compile and execute const TCHAR cEscape = (const TCHAR)-16; the value of the cEscape variable (as seen in quickwatch window in VC++ debugger) is 65520 I am wondering should the value of the cEscape variable be 240 which is unsinged char equivalent of signed char -16 or the value 65520 is correct? Can someone please clarify? Thanks and Regards :)

            M Offline
            M Offline
            Mike Dimmick
            wrote on last edited by
            #5

            The C++ standard does not dictate whether char is signed or unsigned. The default for char in Visual C++ is signed (but this can be changed with a compiler option). wchar_t is a typedef for unsigned short in older compilers and so is always unsigned. This sounds like a value that is not used as a character, only as an 8-bit integer, and you should leave it as char rather than blindly converting to TCHAR. You should evaluate all uses of char carefully as it sounds like a codebase where a BYTE typedef was not used.


            DoEvents: Generating unexpected recursion since 1991

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups