C Introduction Flashcards

1
Q

Phases of compiling and running C programs

A

1) Program is created using editor and stored on disk
2) Preprocessor program processes the code
3) Compiler creates the object code and stores it on disk
4) Linker links object code with libraries, create .out and stores on disk
5) Loader puts program in memory
6) CPU takes each instruction and executes it, storing new data values as the program executes.

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

Four types of files for compilers

A
  • source code files
  • header files
  • object files
  • binary executable files
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Source Code files

A

Contain function definitions.

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

Header files

A

Contain function declarations, various preprocessor statements and allows source files to access externally-defined functions.

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

Object files

A

The output of the compiler, and contains function definitions in binary form.
These are also not executable by themselves

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

Binary Executable files

A

The output of the linker, and made from object files.
These can be directly executed.

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

The Preprocessor (cpp or c preprocessor)

A

Before the C compiler starts compiling a source code file, the file is processed by the preprocessor.
Invoked automatically by compiler before compilation properly begins.
Converts source code files.

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

Preprocessor commands

A

Start with a hashtag.

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

include

A

Accesses function definitions defined outside the source code.

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

define

A

Mainly defines constants.

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

Other preprocessor examples

A

if

#else
#elif
#endif
#error

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

The Compiler

A

After the preprocessor includes all header files and expands out all the preprocessor statements, the compiler then can compile the program.
Turns the source code file into an object code file, which contains the binary version of the source code, not the executable version.

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

Invoking the compiler

A

May be invoked as either
% gcc foo.c
or
% gcc -c foo.c
This tells the computer to run the preprocessor on the file foo.c, and then compile it into an object file foo.o.

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

-c

A

In the second example, -c means the we compile the source code into an object file but we do not invoke the linker.

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

Invoking the compiler (one source code file):

A

% gcc foo.c -o foo
This tells the compiler to run the preprocessor on the file foo.c, compile, and link it to create an executable called foo.exe.

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

-o

A

-o states the name of the output binary executable file.

17
Q

The Linker (ld)

A

Links object files together into a binary executable.
Is invoked automatically when using the compiler.

18
Q

Using the linker

A

% gcc foo.o bar.o baz.o -o myprogram

19
Q

Executing a file

A

% ./myprogram