Article View: comp.sys.atari.st
Article #24333C Compiler Startup Code
From: HOWESDW
Date: Thu, 08 Jan 1987 20:59
Date: Thu, 08 Jan 1987 20:59
54 lines
3024 bytes
3024 bytes
Received: by WSUVM1 (Mailer X1.23) id 7097; Thu, 08 Jan 87 12:57:14 PLT
Date: Thu, 08 Jan 87 12:56:28 PLT
From: Don Howes <HOWESDW@WSUVM1>
Subject: C Compiler Startup Code
To: INFO-ATARI16@SCORE.STANFORD.EDU
In a recent posting, Moshe Braner asked why the code generated by a C
compiler is longer than that for an equivalent assembler program, and if
it would be possible to eliminate the additional code. In a word, the
answer to that is no, since the additional code is generated by the
compiler to handle program startup and termination.
(The following discussion is abstracted from: Rex Jaeschke, 1986,
"Solutions in C", chapter 6, Program Startup and Termination, pp. 169-194.,
see his account for the details)
Unlike other programming languages, C does not make a distinction beteen
the main() function and other C functions. In addition, the ability to pass
arguments to main() (argc, argv) suggests the presence of additional code
which calls main() and acts as the actual entry point for the program. This
code, generally called _main, is the startup code for the compiler and is
present in every program generated by the compiler.
The startup code preforms a number of tasks, such as:
(1) setting up the stack for the definition of auto variables and the storage
of function argument lists.
(2) reserving space for the heap, to perform dynamic memory allocation by
malloc() and calloc().
(3) ensuring the correct opening of the files, "stdin", "stdout", "stderr".
(4) passing "argc" and "argv" to main().
(5) ensuring the graceful termination of the program.
(6) an additional series of environment specific functions related to the
hardware/software environment (variable).
To check for the size of the startup code for your compiler, compile and
link the shortest legal C program:
main()
{}
Here are the results from some compilers I have access to, to compare
against:
Ecosoft Eco-C88 (MSDOS) 1536 bytes
Datalight C (MSDOS) 2674 bytes
Microsoft C 4.0 (MSDOS) 1986 bytes
Alcyon C (pre 4.14) (GEM) 6271 bytes
The much larger size for the Alcyon compiler may be related to a more
complex environment, or simply to bloated code. What do other people get
for their ST C compilers?
Don Howes HOWESDW@WSUVM1 (BITNET)
Technical Details
Message-ID:
<8701082100.AA14694@ucbvax.Berkeley.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-lcc!mordor!styx!ames!ucbcad!ucbvax!wsuvm1.BITNET!HOWESDWShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-lcc!mordor!styx!ames!ucbcad!ucbvax!wsuvm1.BITNET!HOWESDW From: HOWESDW@wsuvm1.BITNET Newsgroups: comp.sys.atari.st Subject: C Compiler Startup Code Message-ID: <8701082100.AA14694@ucbvax.Berkeley.EDU> Date: Thu, 8-Jan-87 15:59:34 EST Article-I.D.: ucbvax.8701082100.AA14694 Posted: Thu Jan 8 15:59:34 1987 Date-Received: Thu, 8-Jan-87 23:38:36 EST Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: HOWESDW%WSUVM1.BITNET@forsythe.stanford.edu Organization: The ARPA Internet Lines: 54