CS211: (Appendix) Hosted Environment
Table of Contents
Introduction
At all times when we are compiling and running C programs in the class we are doing so within the confines of a Linux Operating System. This is not something that can be ignored! Within the context of the C runtime specification this is what is called the hosted environment, referring to the fact that the C code is not being run independant of an OS.
The Hosted Environment
The C specification demands that "the function called at program startup is named main…It shall be defined with a return type of int and with no parameters…or with two parameters…" (ยง 5.1.2.3.2) This gives us the reason why we've kept writing int main over and over and over again! Similarly when exiting the function:
If the return type of the main function is a type compatible with int, a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument; reaching the } that terminates the main function returns a value of 0. If the return type is not compatible with int, the termination status returned to the host environmentis unspecified.