<p>I am looking for a more technical explanation than the OS calls the function.</p>
<p>Is there a website or book?</p>

[{'answer_id': 12353, 'author': 'Vincent Robert', 'author_id': 268, 'author_profile': 'https://Stackoverflow.com/users/268', 'pm_score': 3, 'selected': False, 'text': '<p><code>main()</code> is part of the C library and is not a system function. I don\'t know for OS X or Linux, but Windows usually starts a program with <code>WinMainCRTStartup()</code>. This symbol init your process, extract command line arguments and environment (<code>argc, argv, end</code>) and calls <code>main()</code>. It is also responsible of calling any code that should run after <code>main()</code>, like <code>atexit()</code>.</p>\n\n<p>By looking in your Visual Studio file, you should be able to find the default implementation of <code>WinMainCRTStartup</code> to see what it does.</p>\n\n<p>You can also define a function of your own to call at startup, this is done by changing "entry point" in the linker options. This is often a function that takes no arguments and returns a void.</p>\n'}, {'answer_id': 12408, 'author': 'Will Dean', 'author_id': 987, 'author_profile': 'https://Stackoverflow.com/users/987', 'pm_score': 6, 'selected': True, 'text': "<p>The .exe file (or equivalent on other platforms) contains an 'entry point' address.  To a first approximation, the OS loads the relevant sections of the .EXE file into RAM, and then jumps to the entry point.</p>\n<p>As others have said, this entry point will not be 'main', but will instead be a part of the runtime library - it will do things like initialising static objects, setting up the <em>argc</em> and <em>argv</em> parameters, setting up standard input, standard output, standard error, etc.   When it's done all that, it will call your main() function.  When main exits, the runtime goes through an analogous process of passing your return code back to the environment, calling static destructors, calling _atexit routines, etc.</p>\n<p>If you have Microsoft tools (perhaps not the freebie ones), then you have all the runtime source, and an easy way to look at it is to put a breakpoint on the closing brace of your main() method, and single step back up into the runtime.</p>\n"}, {'answer_id': 12452, 'author': 'Aidan Ryan', 'author_id': 1042, 'author_profile': 'https://Stackoverflow.com/users/1042', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://books.google.com/books?id=wZoQyVi5f60C&amp;printsec=frontcover&amp;dq=expert+c%2B%2B%2Fcli&amp;ei=MKylSPz2JJOaigHlkLn7BA&amp;sig=ACfU3U36tvex7dO7wVyGtuy1arcJuU3N0g" rel="nofollow noreferrer">Expert C++/CLI</a> (check around page 279) has very specific details of the different bootstrap scenarios for native, mixed, and pure CLR assemblies.</p>\n'}, {'answer_id': 30840, 'author': 'diciu', 'author_id': 2811, 'author_profile': 'https://Stackoverflow.com/users/2811', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s OS dependent.\nIn OS X, there\'s a frame in the mach header that contains the start address for the EIP (instruction pointer) register.</p>\n\n<p>Once the binary is loaded, the OS launches execution from this address:</p>\n\n<pre>\ncristi:test diciu$ otool -l ./a.out | grep -A 10 LC_UNIXTHREAD\n        cmd LC_UNIXTHREAD\n    cmdsize 80\n     flavor i386_THREAD_STATE\n      count i386_THREAD_STATE_COUNT\n[..]\n        ss  0x00000000 eflags 0x00000000 eip 0x00001f8c cs  0x00000000\n[..]\n</pre>\n\n<p>The address is the address of the "start" function from the binary:</p>\n\n<pre>\ncristi:test diciu$ nm ./a.out\n0000200c D _NXArgc\n00002008 D _NXArgv\n00002000 D ___progname\n00001fe0 t __dyld_func_lookup\n00001000 A __mh_execute_header\n[..]\n00001f8c T start\n</pre>\n\n<p>In Mac OS X, it\'s the "start" function that gets called first, even before the "main" function:</p>\n\n<pre>\n(gdb) b start\nBreakpoint 1 at 0x1f90\n(gdb) b main\nBreakpoint 2 at 0x1ff4\n(gdb) r\nStarting program: /Users/diciu/Programming/test/a.out \nReading symbols for shared libraries ++. done\n\nBreakpoint 1, 0x00001f90 in start ()\n</pre>\n'}, {'answer_id': 33300, 'author': 'Anders', 'author_id': 3501, 'author_profile': 'https://Stackoverflow.com/users/3501', 'pm_score': 3, 'selected': False, 'text': '<p>As far as Windows goes, the entry point functions are:</p>\n<ul>\n<li>Console: <code>void __cdecl mainCRTStartup( void ) {}</code></li>\n<li>GUI: <code>void __stdcall WinMainCRTStartup( void ) {}</code></li>\n<li>DLL: <code>BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL,DWORD fdwReason,void* lpReserved) {}</code></li>\n</ul>\n<p>The only reason to use these over the normal <em>main</em>, <em>WinMain</em>, and <em>DllMain</em> is if you wanted to use your own run time library. (If you want smaller file size or custom features.)</p>\n<p>For custom run-time implementations and other tricks to get smaller PE files, see:</p>\n<ul>\n<li><a href="https://web.archive.org/web/20030809030037/http://www.microsoft.com/msj/archive/S569.aspx" rel="nofollow noreferrer">http://www.microsoft.com/msj/archive/S569.aspx</a></li>\n<li><a href="http://www.codeproject.com/KB/tips/aggressiveoptimize.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/tips/aggressiveoptimize.aspx</a></li>\n<li><a href="https://web.archive.org/web/20080821121317/http://catch22.net/tuts/minexe.asp" rel="nofollow noreferrer">http://www.catch22.net/tuts/minexe.asp</a></li>\n<li><a href="https://web.archive.org/web/20090223080307/http://hailstorm.net:80/papers/smallwin32.htm" rel="nofollow noreferrer">http://www.hailstorm.net/papers/smallwin32.htm</a></li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/12332', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']