entry at other than main (was want to know)

Badger BA 64810 bbadger at x102c.harris-atd.com
Wed Aug 23 02:07:03 AEST 1989


In article <19210 at mimsy.UUCP> chris at 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 at 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 at trantor.harris-atd.com|'s/./&&/g' Tom sed expansively.



More information about the Comp.lang.c mailing list