want to know

Barry Margolin barmar at think.COM
Thu Aug 17 09:04:56 AEST 1989


In article <2538 at trantor.harris-atd.com> bbadger at 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 at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list