Headerfiles and Makefiles Flashcards

1
Q

What are Header (.h) files?

A

Templates / short snippets of code to be implemented in a .cpp file.

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

Headerfiles and MakeFiles

How are header files added?

A

#include “header_file.h”
(“ “, not < >)

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

What does including a .h file accomplish in a .cpp file?

A

It essentially copies the .h file to the top of the .cpp file.

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

Headerfiles and MakeFiles

As a rule of thumb, what should header files contain?

A
  • Include Guards
  • Definitions and outline for code.
  • Some small simple code, ex getters and setters.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Headerfiles and MakeFiles

Should “using namespace” be used in header files?

A

No, because it will add the code in the .h file to the namespace, rather than add the namespace to the global namespace like in .cpp files.

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

Headerfiles and MakeFiles

How do you access/implement a free floating function from a .h file?

A

Directly using the same footprint as defined in the .h file.

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

Given class method DoStuff(int i); in class MyClass declared in a .h, how would you implement this in a .cpp?

A

With a reference to the class name. (i.e: MyClass::DoStuff(int i) {…}) or with “using namespace MyClass” At the top of the .cpp.

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

What are include guards?

A

A pre-compiler command to tell the compiler not to duplicate .h code if already included.

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

What is the syntax of include guards?

A

#ifndef FILENAME_H

#define FILENAME_H

…some code…

#endif FILENAME_H

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

What is a .o file?

A

A file that contains the machine code representation of your code, but not yet executable.

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

What is a .a file?

A

An archive file that contains a library of compiled .o files.

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

What is the relation between a archive and header files?

A

The .h file acts as a translator between the user and the .a file.

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

What is a Makefile

A

A text file containing a list of commands

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

What are targets in a Makefile?

A

Names of Makefile Commands.

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

What whitespace does a Makefile use?

A

Tabs, not spaces.

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

What is the default command in a Makefile?

A

The first command in a Makefile, or the commands under the ‘all’ target.

17
Q

What is a dependency in a Makefile?

A

A list of commands before the Make target can run.

18
Q

What is the syntax of a Makefile dependency?

A

target : dependencies
ex:
HelloWorld : hello.o

19
Q

If a dependency is not found as a target in a Makefile, what happens?

A

It searches for a file by the same name.

20
Q

What is a Makefile ‘Pattern’?

A

A target that uses a pattern rule to streamline a command.

21
Q

How is a Makefile pattern rule made syntactically?

A

With %. For example, %.o will look for any make command with a .o, and replace % with that command.

22
Q

What does the following code do in a Makefile?
%.o : %.c
g++ –g –Wall –c $<

A

Looks for any make command with .o, searches for the requisite.c, and uses that .c where the $< is.

23
Q

In a Makefile pattern, what does $< represent?

A

Any dependency file for a given target.

24
Q

In a Makefile, what is the ‘.PHONY:’ command?

A

It tells Makefile not to expect a file to be created.

25
Q

What are the 3 compilation flags required for this course?

A
  • Wall
  • Wfatal-errors
  • Werror
26
Q

What is the ‘Wall’ complation flag?

A

All of the basic warnings for unstable code.

27
Q

What is the ‘Wfatal-errors’ complation flag?

A

Any error stops compilation.

28
Q

What is the ‘Werrors’ complation flag?

A

Compiler will treat all warnings as errors.