On Mon, 9 Jan 2006 12:03:34 +0000, Chris Hills <ch***@phaedsys.org>
wrote in comp.lang.c:
In article <43***********************@dreader21.news.xs4all.n l>, Ico
<us****@zevv.nl> writesrobinsonreyna <ro***********@gmail.com> wrote:
Is it possible to write a program which do not have a
main() function.
No
This is not correct.
The program should compile and run.
Not possible
Please give sample code to do this.
Does not exist
It does.
However this is only in special circumstances. In a Hosted system. Ie
one with an operating system you must have
int main(void)
or
int main (argv argc)
in a self hosted system (usually an embedded system) you do not need to
have a main and as there is no OS main can be
You are going overboard here. There are many embedded systems that
have operating systems, yet are "freestanding" environments as defined
the C standard. In fact, I've written operating systems for
freestanding embedded systems, and used others off-the-shelf.
Here is the C standard's definition of a 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."
Note especially the phrase "may take place without the benefit of an
operating system". It does not forbid a freestanding environment from
having an operating system.
As far as the C standard is concerned, the real distinction between
hosted and freestanding environments is this:
"The two forms of conforming implementation are hosted and
freestanding. A conforming hosted implementation shall accept any
strictly conforming program. A conforming freestanding implementation
shall accept any strictly conforming program that does not use complex
types and in which the use of the features specified in the library
clause (clause 7) is confined to the contents of the standard headers
<float.h>, <iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>,
<stddef.h>, and <stdint.h>. A conforming implementation may have
extensions (including additional library functions), provided they do
not alter the behavior of any strictly conforming program."
In other words, a hosted implementation must provide every single
function defined in the standard library for the application to call,
but a freestanding environment does not have provide any standard
library functions at all.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html