C startup in /lib/crt0.o

guy at sun.UUCP guy at sun.UUCP
Tue Apr 29 03:59:43 AEST 1986


> I see that the C startup routine _start in /lib/crt0.o under 4.2BSD
> is a bit over-protective, in that it calls routine _exit (rather than
> the system-call __exit) when it terminates.
> (At least, this is the case >here< - I don't know if its very standard!)

Yes, it is extremely standard.  Just about every UNIX implementation of C
does it (S3, S5, 4.xBSD, probably V7).

> Does anyone know why? (or care, for that matter).

In most UNIX implementations of C, if "main" returns with a given value, the
program acts as if "exit" had been called as if "exit" had been called with
that value.  (Yes, I already know Sun UNIX doesn't do this.)  This is
implicitly stated in the S5 documentation, and very explicitly stated in the
draft ANSI standard for C.  It has nothing whatsoever to do with
"over-protectiveness"; it's a matter of the semantics of the routine "main".

> I suppose it does no harm really (except load in 4k of stdio-library
> garbage, which I could really cope without!).

It only does so in systems like 4.xBSD, which have removed the trick in the
C library which causes the standard I/O library to be brought in only if it
was actually used.  This trick dates back to V7, and is still in S3 and S5.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.arpa



More information about the Comp.bugs.4bsd.ucb-fixes mailing list