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. TCHAR vs built in char

TCHAR vs built in char

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studioquestion
8 Posts 5 Posters 1 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
    Calin Negru
    wrote on last edited by
    #1

    How is TCHAR and char different?

    D L 2 Replies Last reply
    0
    • C Calin Negru

      How is TCHAR and char different?

      D Offline
      D Offline
      den2k88
      wrote on last edited by
      #2

      TCHAR is a macro that is evaluated either as char or unsigned short, depending on the enabling of unicode support. TCHAR is favored for strings because it reduces the risk of misalignemnts between pieces of code that use char and pieces that use short, also allows for a modicum of configurability (in theory you could enable Unicode strings just enabling Unicode support, in practice it's not that simple).

      GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

      L 1 Reply Last reply
      0
      • D den2k88

        TCHAR is a macro that is evaluated either as char or unsigned short, depending on the enabling of unicode support. TCHAR is favored for strings because it reduces the risk of misalignemnts between pieces of code that use char and pieces that use short, also allows for a modicum of configurability (in theory you could enable Unicode strings just enabling Unicode support, in practice it's not that simple).

        GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        den2k88 wrote:

        in practice it's not that simple

        It can be if you use all the correct macros. I have a number of projects where it works seamlessly.

        D 1 Reply Last reply
        0
        • L Lost User

          den2k88 wrote:

          in practice it's not that simple

          It can be if you use all the correct macros. I have a number of projects where it works seamlessly.

          D Offline
          D Offline
          den2k88
          wrote on last edited by
          #4

          It is if you use all the correct macros and good programming practices. Which, on large and/or legacy projects with multiple programmers in space and time, is not necessarily a valid assumption, sadly.

          GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

          K 1 Reply Last reply
          0
          • C Calin Negru

            How is TCHAR and char different?

            L Offline
            L Offline
            leon de boer
            wrote on last edited by
            #5

            The overwhelming use of it is when you want to use unicode but have the code portable for the none unicode situation. It isn't just TCHAR you use in that situation but you place all string literals inside the _T() or TEXT() macros so they also port and use the TCHAR string functions _tcslen for strlen, _tcscpy_s for strcpy_s etc so all the string functions port. So being precise about this on Visual Studio with a project open goto the last debug menu which is the project properties then goto Configuration Properties->Advanced->Character Set you now have 3 options not set (aka use ansi), use unicode and use multi-byte wide character. When you use TCHAR and the above macros and stuff in you can compile your code in any of those modes and it will work completely seamlessly. I use it a lot because I write many multilingual windows applications which have large use in non English language areas. It becomes second nature like using stdint.h and proper sized integers rather than int, short, long etc which are problematic porting.

            In vino veritas

            C 1 Reply Last reply
            0
            • L leon de boer

              The overwhelming use of it is when you want to use unicode but have the code portable for the none unicode situation. It isn't just TCHAR you use in that situation but you place all string literals inside the _T() or TEXT() macros so they also port and use the TCHAR string functions _tcslen for strlen, _tcscpy_s for strcpy_s etc so all the string functions port. So being precise about this on Visual Studio with a project open goto the last debug menu which is the project properties then goto Configuration Properties->Advanced->Character Set you now have 3 options not set (aka use ansi), use unicode and use multi-byte wide character. When you use TCHAR and the above macros and stuff in you can compile your code in any of those modes and it will work completely seamlessly. I use it a lot because I write many multilingual windows applications which have large use in non English language areas. It becomes second nature like using stdint.h and proper sized integers rather than int, short, long etc which are problematic porting.

              In vino veritas

              C Offline
              C Offline
              Calin Negru
              wrote on last edited by
              #6

              That sheeds light on it. Thanks for taking time to write that down and share your knowledge leon.

              `DreamLand Page` on facebook

              1 Reply Last reply
              0
              • D den2k88

                It is if you use all the correct macros and good programming practices. Which, on large and/or legacy projects with multiple programmers in space and time, is not necessarily a valid assumption, sadly.

                GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                K Offline
                K Offline
                kalberts
                wrote on last edited by
                #7

                Why does "sadly" sometimes make me smile? :-)

                D 1 Reply Last reply
                0
                • K kalberts

                  Why does "sadly" sometimes make me smile? :-)

                  D Offline
                  D Offline
                  den2k88
                  wrote on last edited by
                  #8

                  I've seen things. We all have seen things.

                  GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                  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