I’m writing some C code and use the Windows API. I was wondering if it was in any way good practice to cast the types that are obviously the same, but have a different name? For example, when passing a TCHAR * to strcmp(), which expects a const char *. Should I do, assuming I want to write strict and in every way correct C, strcmp((const char *)my_tchar_string, "foo")?
I’m writing some C code and use the Windows API. I was wondering if
Share
Don’t. But also don’t use
strcmp()but rather_tcscmp()(or even the safe alternatives)._tcs*denotes a whole set of C runtime (string) functions that will behave correctly depending on howTCHARgets translated by the preprocessor.Concerning safe alternatives, look up functions with a trailing
_sand otherwise named as the classic string functions from the C runtime. There is another set of functions that returnsHRESULT, but it is not as compatible with the C runtime.