A
Amandil
I was wondering if anyone out there can point me in the right
direction, and tell me which newsgroup I can go to where my question
can be answered. I do realize that my question may be off-topic, and
is definitely operating system and compiler specific. So, here goes.
I wanted to know, who calls main(). Many C books have the line, "In
effect, the operating system calls main()." Actually, main() is called
by some function (probably) within the C library (not programmmer-
accessible), which is responsible for setting up the environment in
which the program executes, like allocating FILE objects for stdin/
stdout and setting up argc and argv (and envp - IS). This function
also performs clean up afterwards, like calling exit() with the return
value of main(). Obviously, this needn't be a function, and the
compiler can just place code that does this at the beginning and end
of main(). (I would see this as an inline function.)
Obviously, there is no one answer - it's very implementation specific
- and within standard C, there is no need to know, and it wouldn't
help me if I did. On the other hand, someone writing a compiler does
need to know that information, and in practice write the code as well.
I am looking for specific code examples, for different OS's, so I can
compare and perhaps write my own.
Does anyone have an address for me? Thanks, and I'll appreciate not
being flamed.
-- Marty Wolfe
direction, and tell me which newsgroup I can go to where my question
can be answered. I do realize that my question may be off-topic, and
is definitely operating system and compiler specific. So, here goes.
I wanted to know, who calls main(). Many C books have the line, "In
effect, the operating system calls main()." Actually, main() is called
by some function (probably) within the C library (not programmmer-
accessible), which is responsible for setting up the environment in
which the program executes, like allocating FILE objects for stdin/
stdout and setting up argc and argv (and envp - IS). This function
also performs clean up afterwards, like calling exit() with the return
value of main(). Obviously, this needn't be a function, and the
compiler can just place code that does this at the beginning and end
of main(). (I would see this as an inline function.)
Obviously, there is no one answer - it's very implementation specific
- and within standard C, there is no need to know, and it wouldn't
help me if I did. On the other hand, someone writing a compiler does
need to know that information, and in practice write the code as well.
I am looking for specific code examples, for different OS's, so I can
compare and perhaps write my own.
Does anyone have an address for me? Thanks, and I'll appreciate not
being flamed.
-- Marty Wolfe