CONTENTS | INDEX | PREV | NEXT
c.a
NAME
c.a - DICE startup module for all C programs
SYNOPSIS
c.a is entered when the program segment is run
FUNCTION
DCC specifies DLIB:C.O first when linking objects into an
executable. C.O also exists in C.LIB but is not normally pulled
since it is already included in the link line.
C.O does the following:
(1) save non-scratch registers
(2) If Resident:
Allocate space for both data & bss and copy the
initialized data into the allocated space. Clear
the BSS portion of the data space
Else
The BSS has already been allocated by the load module
but not cleared, Clear the BSS portion of the data space
(3) Clear the ^C signal
(4) Setup _SysBase
(5) Call all AUTOINIT subroutines (this usually results in at
least the dos.library being openned).
(6) call _main() (usually in c.lib as well)
(7) fall through to _exit(0)
Note that while c.a falls through to _exit(0) after calling _main(),
_main itself calls main() with: exit(main(args...)); Thus, main()
is always expected to return a valid value (i.e. not void).
C.O also handles the low level exit _exit() (__exit:) in the
following sequence:
(1) Call autoinit exit subroutines (this normally closes the
DOS library and other automatically openned libraries such
as floating point libraries).
(2) Free all memory allocated by the task, including the small
data segment & BSS space. Note that all variables that we
use after this have already been placed in registers since
the dataspace is no longer valid.
(3) If the _WBMsg is not NULL then:
(a) Forbid()
(b) ReplyMsg(_WBMsg)
(4) restore original registers and rts (exit out of the process)
NOTE
Normally the programmer does not overide the startup object file
(c.o) since this is the entry point into the program. However, in
many cases a programmer will want to overide _main(). I.E.:
_main(len, arg)
int len;
char *arg;
{
...
}
In which case he is given the length and arg pointer passed to the
program on startup. When you overide _main() you cannot call any
stdio (fopen, fclose, puts, etc...), low level IO (open, close,
read, write, etc...), or memory allocation routines.
Normally _main will be overriden if the program makes only system
calls (such as Open, Close, Read, Write, FindTask, etc...).
Overriding the c.lib generally makes executables much smaller as no
extranious stdio/low level IO routines are brought in from c.lib .
Normally you exit out of _main by calling _exit(code) (note the
underscore).