Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!unmvax!bbx!bbxeng!scott From: scott@bbxeng.UUCP (Engineering) Newsgroups: comp.lang.c Subject: Re: entry at other than main (was want to know) Message-ID: <189@bbxeng.UUCP> Date: 21 Aug 89 22:51:58 GMT References: <8487@bsu-cs.bsu.edu> <2980@solo9.cs.vu.nl> <182@sunquest.UUCP> <2563@trantor.harris-atd.com> <19164@mimsy.UUCP> <15127@dartvax.Dartmouth.EDU> Reply-To: scott@bbxeng.UUCP (Scott-Engineering) Organization: Basis International, Albuquerque, NM Lines: 47 In article <15127@dartvax.Dartmouth.EDU> ari@eleazar.dartmouth.edu (Ari Halberstadt) writes: >In article <19164@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >>In many articles many people write this, that, and the other argument >>for or against `main()' as the program entry point. >[lots of very good arguments] > >Ok, there's actually a very simple way to do this. Just have an option >to the linker telling it what the entry point is. This is done on the >Macintosh with MPW. [flame on] OK. For the *last time*, folks: There is nothing *special* about 'main'. The UNIX/XENIX linker doesn't give a $&#$# about 'main'. Before a 'C' program can execute, a startup routine must be executed to set up a few things (such as the arguments to main()). This startup routine is usually found in the file 'crt0.o'. When the linker is called from the 'C' compiler, the file 'crt0.o' is quietly given as the first module in the link. The linker simply considers the first instruction in the first module to be the entry point. Some linkers will vary but the idea is the same - there is an known entry point in 'crt0.o'. (Perhaps the symbol table for 'crt0.o' contains an explicit entry point). If you invoke 'ld' yourself you must remember to include 'crt0.o' or you will probably get error messages. Once 'crt0.o' does its thing *it* calls main(). If you want *it* to call some other routine then either modify the source for 'crt0.o' or write your own startup routine. Please understand, 'main' is *not* the entry point to your program as far as UNIX is concerned. It may *appear* to be the entry point in *your* code because of a (usually invisible) startup routine that is designed that way. I, for one, have not lost any sleep over this. [flame off] -- --------------------------------------- Scott Amspoker Basis International, Albuquerque, NM 505-345-5232