Separate Compilation Flashcards

1
Q

In general what is seperate compilation in C++?

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

When one file needs to refer to another (e.g. LinkedList needs a NOde), what do we use to ensure that we can do this?

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

Specifically how do you use a guard when including items. What does it do?

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

What would intAtom.cpp look like for the following:

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

In general, how should you approach includes for both .cpp and .h files?

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

Why don’t guards solve all our include problems?

A

Every .cpp file is compuled separately into an object file and THEN they are linked together.

  • Guards only stop you from including something more than once in ONE file compilation (e.g. if you included ListItem and Node, and Node was including ListItem too)
  • Guards DON’T stop two seperate instance existing in two different translation units (i.e. the contents of a single source file, plus the contents of any header files directly or indirectly included by it)
    • e.g. if you included ListItem and so did some other file compiled seperately
  • Inclusion of two header files in two seperate spots doesn’t caus ea problem if there’s no executable code - it’s only being brought in so the ompiler can get enough context to compile the class it is working on.
    • BUT if there’s any executable code(e.g. a method that is not inline*, a variable initialization…) you’ll get two copies of executable code in your compilation if you do two includes of the header.
    • The link editor will then produce errors because it doesn’t ahve a unique place to link to.
    • *an inline method is exempt from the “One Definition Rule” (ODR)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the solution to the include problem in C++?

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

For the attached code (which represents GenericList.h):

  1. Why do we need to include ListItem.h
  2. Why don’t we need to include Node.h?
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In C++ what is a forward reference and how do you make one?

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

In the attached code (in GenericList.h):

Why does class Node work?

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

What are good general rules for including/forward referencing?

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

When should you use #include?

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

When are other instanaces would you use forward references

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

In the included code, why use a forward reference to C2.

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

In the attached code, do we need the forward reference class ListItem. Why/Why not?

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

In terms of header files and source files, how does one create an Abstract class?

A
17
Q

In general how do you compile with seperate compilation?

A
18
Q

How do you compile each .cpp file seperately?

A
19
Q

Once you have compiled each .cpp file seperately, how do you link them together to form an executable?

A
20
Q

In general, what is the syntax for a Makefile?

A
21
Q

How would you create a makeFile for the following files:

A
22
Q

How should you handle static members in Seperate Compilation?

A
23
Q

What are the 3 varieties strings come in, in C++?

A
24
Q

How do you use type def in C++?

A
25
Q

What should you know about C++ and arrays?

A
26
Q

How do you define and assign a pointer to an array (or array entry)?

A
27
Q

How would you use a pointer in an array with a for loop?

A