entry at other than main (was want to know)

Chris Torek chris at mimsy.UUCP
Wed Aug 23 00:16:17 AEST 1989


>In article <19164 at mimsy.UUCP> I listed some ways to start a program:
>>We have four standard approaches available:
>>	a) program begins at procedure or function declared with
>>	   some special syntax;
>>	b) program begins at top;
>>	c) program begins at reserved name (`main');
>>	d) program begins at any function (Lisp, APL, etc).

In article <657 at philmtl.philips.ca> ray at philmtl.philips.ca (Raymond Dunn)
writes:
>A fifth approach in use that Chris seems to have missed:
>
>	e) program begins at the external symbol specified at link time.

Actually, I left this one out for two reasons.  As Doug Gwyn has
already pointed out, this makes life difficult for languages that need
runtime startup actions (such as C, Pascal, and FORTRAN, on many
machines, including most of those on which this article is being
read).  The other is that it makes for lost information.

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
this is not all.  For instance, many compilers have to alter external
symbols in some manner.  (Unix compilers typically prepend an
underscore; others map to uppercase and elide underscores, or add
trailing periods, or do use less describable transform.)

The latter problem can be solved by making sure the compiler gets
to rewrite the symbol at link time (so that the same transformation
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



More information about the Comp.lang.c mailing list