Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!decvax!decwrl!ucbvax!hadron.UUCP!jsdy From: jsdy@hadron.UUCP.UUCP Newsgroups: mod.computers.vax Subject: Re: main() and entry points in C Message-ID: <8607150515.AA00312@hadron.UUCP> Date: Tue, 15-Jul-86 01:15:13 EDT Article-I.D.: hadron.8607150515.AA00312 Posted: Tue Jul 15 01:15:13 1986 Date-Received: Wed, 16-Jul-86 17:42:08 EDT References: <870@bu-cs.UUCP> Sender: daemon@ucbvax.BERKELEY.EDU Organization: Hadron, Inc., Fairfax, VA Lines: 64 Approved: info-vax@sri-kl.arpa Newsgroups: net.lang.c Subject: Re: Request for Comments Summary: Combatting nonsense! In article <870@bu-cs.UUCP> bzs@bu-cs.UUCP (Barry Shein) writes: >Any comments? This is taken from INFO-VAX (mod.computers.vax): >Path: bu-cs!harvard!caip!think!nike!styx!YALE.ARPA!LEICHTER-JERRY >From: LEICHTER-JERRY@YALE.ARPA >Subject: Re: main() and entry points in C >Date: Thu, 26-Jun-86 08:50:52 EDT > > ... Thus, _start == NULL. Most users will never see this, >but an implementer of _start() would. If some implementation of C uses _start instead of start as an entry point, they are asking for trouble. I have never seen a C-accessible symbol as an entry. The entry point, start, used to be almost always 0; but it isn't ever 0, now, in the latest releases of AT&T System V Unix. > -- still going to bet that the first routine WON'T end up as the entry > point? > I won't bet on anything if the loader isn't invoked properly.... >That gets to the crux of things: The "proper" way to invoke the loader is >undocumented - you must use cc. How then do you deal with a program written >in multiple languages? Basically, you ask a wizard.... On many versions of Unix, it is documented that properly written multiple-language modules can be compiled together by appropriately calling the compiler: cc myc.c myftn.o ... or f77 myftn.f myc.o ... or even f77 myftn.f myc.c ... > .. Since the "entry point is the first routine" IS, in fact, >documented - even if only for wizards! - supporting it couldn't hurt.... You claim this is a documented undocumented feature? It isn't even true. Specifically, never_called() { printf("Hi. Joe is wrong.\n"); } main() { printf("Hello world.\n"); } will never call me a liar. Even if you are talking about straight link-loaded objects (with no header to call _main()), several common loaders allow one to specify entry points other than 0. These include, but are not! limited to, the AT&T System V ld (again); the CULC Fortran IV Plus linker; and the DEC VMS linker. The C header, which cc puts at the head of the compiled objects, contains the entry point -- which is not at location 0 under all versions of Unix! This header moves the argc, argv, and envp to a location that main() will understand when called as a function; then calls main() as a function; then calls exit() as a function whose argument is main()'s return value; and if this doesn't exit, typically tries to perform an exit system call itself, and then (in desperation) a halt. I should say it TYPICALLY does all this. If it ain't documented (and especially if it's not in the standard), it ain't guaranteed, so don't bet the lunch money, Mildred. -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP} jsdy@hadron.COM (not yet domainised)