Brett McCoy wrote:
> On Sat, May 24, 2008 at 10:46 PM, odbapsvm <[EMAIL PROTECTED]> wrote:
>   
>> Sorry, I meant to ask where is the prototype
>> for the main function?
>>     
> There isn't one. It's declared and defined in the same place. Your
> compiler "knows" what to do when it compiles a source file with main()
> in it.
>   

This is the beauty of interfacing. All you need to know is that if you 
provide a main() method with a specific interface, your program runs. 
The operating system needs to know that if it finds an executable, it 
will have an entry point with a specific interface. The compiler takes 
care of the dirty work.

Without providing too many boring details that might confuse you, the 
gist of it is this. The operating system calls a function. This function 
is prebuilt by the compiler to set up your stack, load the standard 
library, create the command-line arguments that pass into your program, 
and set up other boring mundane stuff. It then passes control over to 
main() when it is done, and cleans up and returns to the OS when your 
main() is complete. The important thing is that you provide a function 
with an interface, and some magical unicorn creature calls this function 
to run your program. Do not taunt the unicorn. It is real, even if you 
cannot see it. I promise.

-- 
John Gaughan

Reply via email to