C3: The C Building Process Flashcards

1
Q

What does a source code file include?

A

types, variables, functions,

comments, statements, directives

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a statement in C?

A
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 { { } }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give an example of a statement.

A
 a function call
 a control flow statement
 a block
 an expression (see later)
 a (variable or type) declaration
 a function prototype
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the Pre-processor do?

A
Removes comments
 Modifies source code
according to preprocessor directives
 Most importantly:
includes header files into
source code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a file that ends in .h?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the steps to compiling a program in C?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the Linker do?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an .o file and what does it contain and export?

A

= 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an unresolved identifier?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a .s file?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is dynamic data?

A

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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Name two different definitions for a heap.

A
  1. A heap (data structure) is a tree-based data structure
  2. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the definition of a heap in the C Loader?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is memory leak?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly