C Program With NO Main Function
C Program With NO Main Function
To understand why some C programs does not require a main() function it is necessary to
understand concept called Execution Environment :
Execution Environment:
Hosted Environment:
Hosted environment is one which a normal developer encounters everyday while writing a
piece of code. It already provides inbuilt support of most of the standard libraries and
functions. In Hosted environment the developer does not need to worry about the basic
functionally required eg I/O functionality provided by “stdio.h” . GCC is one such platform
which provides a Hosted environment which may itself be running on any OS like Linux.
Andalso starting point of any hosted environment is the “main function”. Implementations
use a variety of techniques to start executing a program image. These usually involve
executing some internal, implementation-specific, function before main is called. Then
association between this internal function and main is usually made at link-time by having the
internal function make a call to “main function “, which is resolved by the
linker in the same way as other function calls. To sum-up hosted environment provides a lot
of standard library functions which may or may not be needed by developer but are provided
by default.
Freestanding Environment:
Freestanding environment on the other hand is intended to interact directly with the hardware.
A freestanding environment does not require any built in library functions. A freestanding
implementation is one in which execution may take place without the benefit of an operating
system, and has an implementation-defined set of libraries that include certain language-
support libraries
start_kernel() .
In most of these cases the code on freestanding environment is used by developers who
cannot afford to have all the unnecessary libraries or does not require them like the
Embedded System developers .
However there are some libraries which are needed by both hosted and freestanding
environment . They are listed Below :
These libraries fulfil basic needs of C programming and come as a part of Standard
Libraries .