C3: The C Building Process Flashcards
What does a source code file include?
types, variables, functions,
comments, statements, directives
What is a statement in C?
The ‘commands’ of the C language They are executed to perform the actions of the program They can span multiple lines and usually end with ; A C program is formed by a sequence of one or more statements A block { } is a compound statement Blocks can be nested { { } }
Give an example of a statement.
a function call a control flow statement a block an expression (see later) a (variable or type) declaration a function prototype
What does the Pre-processor do?
Removes comments Modifies source code according to preprocessor directives Most importantly: includes header files into source code
What is a file that ends in .h?
It is a header file. it contains types, variables, function declarations, macros. it is used to define API. The pre-processor includes it in the translation unit through a preprocessor directive and the linker resolves this reference (which is listed in symbol table) by linking function/variable implementations with object code.
What are the steps to compiling a program in C?
Step 1: Pre-Processor. Removes comments, reads pre-directives, includes header files. Output: Translation Unit,
Step 2: Compiler. Performs correctness checks, code optimizations. Output: assembler code (.s file),
Step 3: Assembler. Translates assembler code (.s file) into binary machine instructions/object code (.o file),
Step 4: Linker. Combines multiple object files into a single file, Output: exe file.
What does the Linker do?
resolves unresolved symbols.. The linker reads the set of provided (resolved) identifiers (symbols) and set of required (unresolved) identifiers. Linker matches the identifiers. The linker decides which implementation to use for a called function that is defined outside its own translation unit.
What is an .o file and what does it contain and export?
= object file. It is a binary file that contains all instructions and data resulting from the translation process (output of assembler).
• Cannot be executed directly
It has a header, sections (text, data, bss) and a symbol table containing names and locations of all variables and functions referenced in the source code file. (referenced functions ex: printf)
It exports a set of provided (resolved) identifiers/symbols and a set of provided (unresolved) identifiers to the LINKER.
What is an unresolved identifier?
An unresolved identifier is indicated in the symbol table of the object file (the .o file outputed by the assembler). It is a variable or function that is not defined in the same translation unit. The preprocessor includes the location of its implementation with a preprocessor directive, but the linker actually links the reference to the implementation and outputs an executable file.
What is a .s file?
It is the assembler file. It is the output of the compiler and is inputted into the assembler. The compiler performs correctness checks and performs optimisation, adds debugging (optional) and translates source code of translation uni into assembler code.
What is dynamic data?
Dynamic data is stored in the stack. Ex. When a function is called, the variables get memory allocated on to the stack. When the function is over, the variables are deallocated. These variables are “dynamic”
Name two different definitions for a heap.
- A heap (data structure) is a tree-based data structure
- Heap (allocation) is also the name for a memory space that is used for dynamic memory allocation. The memory is allocated during execution of instructions written by programmers. [….] . has nothing to do with heap data structure. It is called heap because it is a pile of memory space available to programmers to allocate and de-allocate. If a programmer does not handle this memory well, memory leak can happen in the program.
What is the definition of a heap in the C Loader?
Heap is also the name for a memory space that is
used for dynamic memory allocation. It grows from bottom to top. Used for allocating memory dynamicaly (for pointers) when programmer aks for it expicitly. It is managed by the C runtime and usually organised as a linked list.
What is memory leak?
Memory leak occurs when programmers create a memory in heap and forget to delete it.
Memory leaks are particularly serious issues for programs like daemons and servers which by definition never terminate.