Home c++ _tmain () Why is such a name?

_tmain () Why is such a name?




Why does such a name gives VS performing functions in the console application?

Answer 1, Authority 100%

everything is simple.

For non-Unicode programs, the corresponding name Main and the list of INT ARGC, CHAR * ARGV [] .

For Unicode programs The parameter list in MSVC looks like int argc, wchar_t * argv [] , and in order to avoid conflicts with source and compilers corresponding to the standard, the function is called WMAIN .

For programs that can compile both in Unicode-, and in non-unicode mode, the list of arguments looks like int argc, _tchar * argv [] , where the macro _tchar defined as char or wchar_t Depending on the value of the _unicode macro. Thus, you need a third name for a function. So it was invented by the name _tmain .

All of this, of course, requires some magic of the linker, who should be able to define Entry Point not only in the Main function, as according to the standard, A and in the WMAIN / _TMain .

If you are sure that you do not need a Unicode application, you can rename the function in Main and give it a list of int argc, char * argv [] to Complimentary standards. Or if you firmly decided that your program will be run only under the WinNT / XP / 7 line (and not Win95 / 98), you can stay on Unicode option and rename the function in WMAIN (respectively, arguments Must be int argc, wchar_t * argv [] ).

late refinement (thanks @alexolut): According to Documentation , _tmain is defined in & lt; tchar.h & gt; using type>as main or WMAIN So in your program will still be either main or wmain .

(and yes, you can omit the parameters, or add the third parameter ENVP , or declare the return type void .)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions