Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The easy way to find out is to stick a breakpoint in <code>main()</code> and take a look:</p> <p><img src="https://i.stack.imgur.com/vDJAu.png" alt="call stack"></p> <p>So technically, the answer to the question is that <code>main()</code> is called from something called <code>start</code>. You don't get the source code for <code>start</code>, but you can look at the assembly code in the debugger if you want. This version is from code built for the simulator:</p> <pre><code>0x1c30: pushl $0 0x1c32: movl %esp, %ebp 0x1c34: andl $-16, %esp 0x1c37: subl $16, %esp 0x1c3a: movl 4(%ebp), %ebx 0x1c3d: movl %ebx, (%esp) 0x1c40: leal 8(%ebp), %ecx 0x1c43: movl %ecx, 4(%esp) 0x1c47: addl $1, %ebx 0x1c4a: shll $2, %ebx 0x1c4d: addl %ecx, %ebx 0x1c4f: movl %ebx, 8(%esp) 0x1c53: movl (%ebx), %eax 0x1c55: addl $4, %ebx 0x1c58: testl %eax, %eax 0x1c5a: jne 0x00001c53 ; start + 35 0x1c5c: movl %ebx, 12(%esp) 0x1c60: calll 0x00001c70 ; main at main.m:9 0x1c65: movl %eax, (%esp) 0x1c68: calll 0x00002376 ; exit 0x1c6d: hlt 0x1c6e: nop 0x1c6f: nop </code></pre> <p>If you create a MacOS X command-line program and put a breakpoint in <code>main()</code>, you'll find that <code>main()</code> is called by <code>start</code> on the desktop, too. The assembly for the Mac version of <code>start</code> isn't exactly the same, but it's very close. So it's a good guess that <code>start</code> is generated for you by the compiler based on the target platform, and that <code>start</code> is the entry point that the operating system looks for when it's launching a program.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload