There are two forms of conforming implementations specified by the c standard:
- Hosted Implementation &
- Freestanding Implementation
There are based on two types of envrionments that the c standard defines as:
- Hosted environment &
- Freestanding environment respectively.
What is freestanding Environment
& What is Hosted Environment
?
A freestanding implementation is one that is designed for programs that are executed without the benefit of an operating system.
For Ex: An OS kernel or Embedded environment would be a freestanding environment.
A program using the facilities of an operating system would normally be in a hosted implementation.
How does a c program execute in these two environments? What is the difference?
How a C program begins execution in both these environment differs.
For an Freestanding environment, the program startup can happen by any implementation defined function. There is no requirement that even a main()
should exist.
So any of the functions definitions mentioned in the question can be valid depending upon implementation for that Freestanding Environment. And their function parameters and return values will have implementation defined meaning, So you will need to check their documentation to know their precise meanings.
Reference:
5.1.2.1 Freestanding environment
In a freestanding environment (in which C program execution may take place without any
benefit of an operating system), the name and type of the function called at program
startup are implementation-defined. Any library facilities available to a freestanding
program, other than the minimal set required by clause 4, are implementation-defined.
For an Hosted environment the standard mandates the program execution begins by execution of a main()
function and it also mandates how this function will be defined.
The specifications for the same are given in:
C99 Standard: 5.1.2.2 Hosted environment
5.1.2.2.1 Program startup
1 The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent; or in some other implementation-defined manner.