Is it advisable to use strcmp or _tcscmp for comparing strings in Unicode versions?
Asked
Active
Viewed 1.9k times
2 Answers
11
_tcscmp()
is a macro. If you define UNICODE
it will use wcscmp()
, otherwise it will use strcmp()
.
Note the types TCHAR
, PTSTR
, etc. are similar. They will be WCHAR
and PWSTR
if you define UNICODE
, and CHAR
and PSTR
otherwise.

asveikau
- 39,039
- 2
- 53
- 68
-
8That is incorrect. `UNICODE` drives the definition of wide character string in the Win32 API. i.e when you `#include
`. `_UNICODE` drives the c-runtimes support for wide (and multi byte) characters, and has meaning when you `#include – Chris Becke Jan 26 '10 at 19:24` (or any of the other c-runtime headers). If `_UNICODE` is defined, `_tcscmp` will be `wcscmp`, else if `_MBCS` is defined, `_tcscmp` will be `_mbcscmp`, else it will be `strcmp`. -
@Chris Becke Hm, I did not know that. I usually define both (with leading underscore and without), and now it makes sense why that's necessary. :-) – asveikau Jan 26 '10 at 21:52
7
No, you should use _tcscmp
. That will resolve to proper function depending upon on your compiler flags.

Naveen
- 74,600
- 47
- 176
- 233