Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: entry at other than main (was want to know) Message-ID: <19210@mimsy.UUCP> Date: 22 Aug 89 14:16:17 GMT References: <8487@bsu-cs.bsu.edu> <2980@solo9.cs.vu.nl> <182@sunquest.UUCP> <657@philmtl.philips.ca> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 46 >In article <19164@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@philmtl.philips.ca> ray@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@mimsy.umd.edu Path: uunet!mimsy!chris