Piling A C Program
Piling A C Program
3. Linking your program with whatever functions are needed from the library
The exact method you use to compile your program will depend upon what
compiler you are using. Also, how linking is accomplished will vary between compilers
and environments; for example, it may be included as part of the compiler or as a stand-
alone application. Consult your compilers documentation for details.
A compiled C program creates and uses four logically distinct regions of memory. The
first region is the memory that actually holds the programs executable code. The next
region is memory where global variables are stored. The remaining two regions are the
stack and the heap. The stack is used for a great many things while your program
executes. It holds the return addresses of function calls, arguments to functions, and
local variables. It will also save the current state of the CPU. The heap is the region of
free memory that your program can use via Cs dynamic memory allocation functions.
Although the exact physical layout of each of the four regions of memory differs
among CPU types and C implementations, the diagram in Figure 1-2 shows conceptually
how your C programs appear in memory
Stack
Heap
Global variables
Program code