Handmade Hero»Forums»Code
19 posts
Q about the series : day 1
Edited by siska on
Hi,

I'm not sure where to post this, but I'm hoping someone will move this to the right forum ... :)


Today, I have accidentally stumbled upon the 'handmadehero' series and I've just finished watching day1 + Q&A.

I think it is brilliant !!! Thank you very much Casey, for doing this massive amount of work for us !

I have 2 questions ... And maybe you will address this later in the series, but just in case ...

* Is there a reason for using C (and not C++) ?
* why did you not start the program with something like int main() { // }; (Why does it have to be Windows-specific) ?

Sorry if these seem like silly questions, but I'm really curious about this. (My background : some (not very fancy) Java, PHP, JS, ...).

Thanks to anyone willing to shed some light !
:)
Mārtiņš Možeiko
2559 posts / 2 projects
Q about the series : day 1
Casey uses C++ not pure C. But he doesn't use all C++ features, just few useful ones - like operator overloading and few others.

To answer second question - Visual Studio C runtime by default expects entry point of your application be named WinMain if you are creating GUI application, and main for console application. That means that using "main" will get you text console open (like cmd.exe does) by default. You can change this behavior by linker flags (http://msdn.microsoft.com/en-us/library/f9t8842e.aspx) But why do that, if you can name your entry point WinMain and as a bonus you'll get hInstance argument, no need to use additional call to get it.
David Owens II
69 posts
A software engineer that enjoys living in enemy territory.
Q about the series : day 1
Edited by David Owens II on
siska

* why did you not start the program with something like int main() { // }; (Why does it have to be Windows-specific) ?


In addition to what @mmozeiko mentions, the entire window creation process is platform specific, so there is no real gain by trying to make the entry point to your application be cross-platform.
19 posts
Q about the series : day 1
Oh ! Interesting !
Thank you both very much. I'll go watch Day2 now ... :)
Mārtiņš Možeiko
2559 posts / 2 projects
Q about the series : day 1
@owensd - that is also a good reason. Windows is not the only one that will have different entry point. Native code on Android starts in ANativeActivty_onCreate if you use NativeActivty directly, or in android_main if you use native_app_glue library.