TCHAR vs built in char
-
How is TCHAR and char different?
-
How is TCHAR and char different?
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
-
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
-
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.
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
-
How is TCHAR and char different?
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
-
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
That sheeds light on it. Thanks for taking time to write that down and share your knowledge leon.
`DreamLand Page` on facebook
-
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