Is it advisable to use strcmp or _tcscmp for comparing strings in Unicode versions?
Is it advisable to use strcmp or _tcscmp for comparing strings in Unicode versions?
_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.
@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. :-) –
Parsimonious
No, you should use _tcscmp
. That will resolve to proper function depending upon on your compiler flags.
© 2022 - 2024 — McMap. All rights reserved.
UNICODE
drives the definition of wide character string in the Win32 API. i.e when you#include <windows.h>
._UNICODE
drives the c-runtimes support for wide (and multi byte) characters, and has meaning when you#include <string.h>
(or any of the other c-runtime headers). If_UNICODE
is defined,_tcscmp
will bewcscmp
, else if_MBCS
is defined,_tcscmp
will be_mbcscmp
, else it will bestrcmp
. – Thevenot