I am new to C++ coding, coming from Java and C# background. I'm puzzled by the proliferation of #define terms starting with the most basic:
#define _tmain wmain
When I first learned a smattering of C ages ago, the main function was:
int main(int argc, char *argv[])
In the Visual C++ project I created, it made the main function:
int _tmain(int argc, _TCHAR* argv[])
I'm just wondering why there needed to be a name translation from wmain to _tmain? Why not just use the original C main function prototype?
In general there seems to be lot of #define renaming something which looks pretty clear to start with, to something which looks more mysterious and less clear (I mean wmain to _tmain ??).
Thanks for tolerating what may be a very obvious question.
This is a Visual C++-specific feature, it's not a part of C++.
Most of the Windows API functions have two versions: those that end in
W, which are for use with wide character strings (wchar_tstrings) and those that end inA, which are for use with narrow character strings (charstrings). The actual Windows API "functions" don't have any suffix and are defined as macros that expand to the right version depending on the settings.The
Tnames (like_TCHARand_tmain) are for the same purpose: they are macros that expand to the right name depending on your compilation settings, sowchar_tandwmainfor wide character support, orcharandmainfor narrow character support.The idea is that if you write your code using the character-type-agnostic names (the
Tnames), you can compile your code to use narrow characters (ASCII) or wide characters (Unicode) without changing it. The tradeoff is that your code is less portable.