View Single Post
Old 03-04-2003, 11:00 AM   #7 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
Re: confirmation

Quote:
Originally posted by saline
The reason the compiler works this way (main on top or prototypes) is because the compiler needs advanced warning about whats going on in the program before it compiles. It needs to allocate (reserve for future use) memory for function calls, variables and other things. It does this so it doesn't run out of memory part way through and crash your computer (among other reasons). When you prototype the top of your program it gives the compiler a concise list of everything your program is going to need before it compiles.
the compiler needs to know what kind of parameters to pass to your function and what kind of parameters to expect in return. memory for function variables is dynamically done on the stack.
if your program runs out of memory (overflows the stack), it will crash itself, but should not crash your computer. modern operating systems use virtual memory systems that keep the program memory space separate from kernel memory. this is not true if you're running an archaeic non-memory protected os like DOS or macos <= 9 (and is partially true for halfassed solutions such as win95/98).

as for calling main(), you can definitely do it. however, there are very few valid reasons for doing so.
joe_bruin is offline   Reply With Quote