Is it advisable to use strcmp or _tcscmp for comparing strings in Unicode versions?
Asked Answered
J

2

9

Is it advisable to use strcmp or _tcscmp for comparing strings in Unicode versions?

Jess answered 21/1, 2010 at 5:22 Comment(0)
P
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.

Parsimonious answered 21/1, 2010 at 5:28 Comment(2)
That is incorrect. 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 be wcscmp, else if _MBCS is defined, _tcscmp will be _mbcscmp, else it will be strcmp.Thevenot
@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
S
7

No, you should use _tcscmp . That will resolve to proper function depending upon on your compiler flags.

Sibella answered 21/1, 2010 at 5:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.