Difference between _tmain() and main() in C
In C , the standard program entry point is main(), which accepts either one of these signatures:
int main(); int main(int argc, char* argv[]);
Microsoft, however, introduced an extension called wmain(), which replaces the second signature with:
int wmain(int argc, wchar_t* argv[]);
To ease the transition between Unicode (UTF-16) and their multibyte character set, Microsoft also defined _tmain() which, when Unicode is enabled, is compiled as wmain, and otherwise as main().
Disparity Between Character Handling
The disparity between main() and _tmain() in your example arises from an incorrect usage of main(). wmain() is designed to accept wchar_t arguments, while main() expects char. Since the compiler is lax in enforcing the correct type for main(), the program interprets the array of wchar_t strings as char strings.
In UTF-16, ASCII characters are represented as a pair of bytes, with the ASCII value followed by a null byte. Since x86 CPUs are little-endian, these bytes are swapped. Thus, in a char string, which is null-terminated, your program sees a series of strings, each a single byte long.
Options for Windows Programming
When working with Windows programming, three main options are available:
It's important to note that these Microsoft-specific extensions do not conform to the C standard, and therefore may not be supported on other platforms.
The above is the detailed content of What's the Difference Between `main()` and `_tmain()` in C Windows Programming?. For more information, please follow other related articles on the PHP Chinese website!