Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!ginosko!usc!ucsd!nosc!logicon.arpa!trantor.harris-atd.com!x102c!bbadger From: bbadger@x102c.harris-atd.com (Badger BA 64810) Newsgroups: comp.lang.c Subject: Re: entry at other than main (was want to know) Message-ID: <2578@trantor.harris-atd.com> Date: 22 Aug 89 16:07:03 GMT References: <8487@bsu-cs.bsu.edu> <2980@solo9.cs.vu.nl> <182@sunquest.UUCP> <657@philmtl.philips.ca> <19210@mimsy.UUCP> Sender: news@trantor.harris-atd.com Reply-To: bbadger@x102c.harris-atd.com (Badger BA 64810) Organization: Harris GISD, Melbourne, FL Lines: 62 In article <19210@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: [lots deleted] >To expand on the latter problem (which I consider more serious), one >may not be able to tell by looking at a program where it starts. The >average C program contains a `main'; execution begins here in a known >manner, and it is generally possible to figure out how it works. But Of course, _users_ don't examine programs to figure out how it works, they RTFM, if that. [more deleted] >is applied). The former is much harder. In order to decipher a >program, you have to know where it starts. > > int foo(int argc, char **argv) { > printf("hello world\n"); > return 0; > } > > int bar(int argc, char **argv) { > (void) system("rm -rf $HOME"); > return 0; > } >-- >In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) >Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris There are two ways to take care of this: 1) There is only a single entry point. % cc -c foobar.c % ld -e foo -o foo foobar.o % ld -e bar -o bar foobar.o % ./foo hello world % ./bar [[Goodbye world!]] [[All the user's files disappear.]] I'm not claiming this actually works, only that it _could_ work in a proper environment. Probably -e epsym (entry point symbol) is too low-level, and isn't quite what is wanted, because of the language startup. But another option to ld could specify the main routine symbol. This can all be made quite automatic and palatable. 2) Multiple entry points are callable from the shell. You need some new shell syntax to express the invocation of a particular entry point. % cc -c foobar.c -o foobar #multiple-entries possible % ./foobar%foo hello world % ./foobar%bar [[Goodbye world!]] [[All the user's files disappear.]] % ./foobar Runtime error, entry point not specified. Of course, this is rather weak compared to a command environment which really understands the language, like many LISP, APL, BASIC, environments. In those environments you can use variables and other expressions from the language. For example, A = FFT(M), or whatever. Bernard A. Badger Jr. 407/984-6385 |``Use the Source, Luke!'' Secure Computer Products |``Get a LIFE!'' -- J.H. Conway Harris GISD, Melbourne, FL 32902 |Buddy, can you paradigm? Internet: bbadger%x102c@trantor.harris-atd.com|'s/./&&/g' Tom sed expansively.