views:

919

answers:

2

hi

For comparing strings in UNICODE versions is it advisable to use strcmp or _tcscmp?

Thanks in advance

+1  A: 

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

Naveen
+4  A: 

_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
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`.
Chris Becke
@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