want to know

Walter Bright bright at Data-IO.COM
Sat Aug 12 06:10:40 AEST 1989


In article <664 at laic.UUCP> darin at nova.UUCP (Darin Johnson) writes:
<In article <2980 at solo9.cs.vu.nl>, roemer at cs.vu.nl (Roemer Lievaart) writes:
<< I always see that people
<< define the function 'main' in C-programs. Why is that? What should it return?
<< Can't I use another name?

Some point has to be the entry point for your program. It's convenient for
that one to be called 'main'. Main is simply a function called from the
startup object file linked in from the library that initializes the program.
You can use another name if you modify the startup code and reassemble it.

<It is a UNIX-ism.  The UNIX linker uses that function name as the name of
<the first routine to jump to.

It has nothing to do with the linker. The startup code calls main. The
startup code contains the start address of the program, and is normally
not associated with any particular name.
It's not a UNIX-ism. It's a C-ism. Other languages, such as Fortran, have
different methods for defining the starting point of the code, and so have
different startup code. The same linker is used.

<Also, for your confusion, most UNIX kernels do not start at main() or even
<have a main()...

That's because they don't use the C startup code.



More information about the Comp.lang.c mailing list