Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.c Subject: Re: want to know Message-ID: <27159@news.Think.COM> Date: 16 Aug 89 23:04:56 GMT References: <8487@bsu-cs.bsu.edu> <2980@solo9.cs.vu.nl> <182@sunquest.UUCP> <14269@haddock.ima.isc.com> <1496@l.cc.purdue.edu> <1701@crdgw1.crd.ge.com> <2538@trantor.harris-atd.com> Sender: news@Think.COM Reply-To: barmar@think.com (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 41 In article <2538@trantor.harris-atd.com> bbadger@x102c.harris-atd.com writes: >Secondly, I don't really like the idea of having a _single_ entry point >to a program. I prefer a scheme which allows any external function to >be called from the command line. You can distinguish a single function >as the main entry. Of course, yo without requiring that it be the _only_ >entry. There are lots of UNIX programs written to simulate this by >switching on the value of argv[0] Multics does precisely what you are describing. On Multics, the shell is basically a user interface to the dynamic linker, so anything that can be called from another program can be invoked from the command line. There are argument restrictions, of course; the shell always passes character string arguments (procedures intended to be invoked as commands use a varargs-like interface). An entrypoint is specified as filename$entrypoint; if there's no "$", the system looks for an entrypoint with the same name as the file, and then for an entrypoint "main_" (for the benefit of programs ported from environments where the main procedure is specified in the program -- e.g. the Multics equivalent of crt0 has a main_ entrypoint that initializes things and calls main). One aspect of Multics that makes this feasible is that no special setup is normally necessary when invoking a command. The entire login session is a single process, so all the process state is already initilized; there's generally no need for anything like crt0 (there actually is something like it for C, because we wanted our C runtime to emulate some Unix behavior, such as freeing everything malloc'ed by a program when it exits or main returns, so you can't use the above mechanism with C on Multics). The way to implement this on Unix is to make a version of exec() that takes an entrypoint name. It would look it up in the file's symbol table, and pass it on to start() (the actual initial routine in crt0). start() would call this address instead of always calling main(). Barry Margolin Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar