int main() or int _tmain() ?

Sep 12, 2016 at 8:37pm
I've been starting to learn about OpenGL and other Graphics Libraries and I've been noticing tutorials and people using "_tmain" instead of main. I have searched and all sources are vague and incomplete.

What is the difference and which/when should I use them?
Sep 12, 2016 at 9:14pm
You should always use int main() or int main(int, char**) (or an equivalent) unless you have to. In other words, if you have to drink a particular vendor's kool-aid.

Only those signatures are valid. I believe that _tmain (and WinMain, is _tmain a macro?) are artifacts of the NT kernel, e.g., of Microsoft.

Similarly, on some platforms (especially freestanding ones), it doesn't make sense for main to ever return, so you'll end up with code like void [[noreturn]] main() { ... }, or on some Unix-like machines you can get to the environment variables by writing int main(int argc, char **argv, char **envp) { ... }, but still, only the first 2 are standard.
Last edited on Sep 13, 2016 at 2:08am
Sep 12, 2016 at 10:57pm
closed account (E0p9LyTq)
http://stackoverflow.com/questions/895827/what-is-the-difference-between-tmain-and-main-in-c
Topic archived. No new replies allowed.