Commit cbbab269 authored by Alexander Hirsch's avatar Alexander Hirsch

Add ex01

parent 15448dc5
......@@ -7,7 +7,7 @@
| 2019-10-15 | [Crap] Git Session |
| 2019-10-22 | [Crap] Scripting Session |
| 2019-10-29 | [Crap] Techniques Session |
| 2019-11-05 | |
| 2019-11-05 | [Infrastructure] |
| 2019-11-12 | |
| 2019-11-19 | |
| 2019-11-26 | |
......@@ -19,6 +19,7 @@
| 2020-01-28 | |
[Infrastructure]: ex01
The lab takes place in [rr15](
# Exercise Sheet 1 — Infrastructure
*due on 5 November 2019*
In this exercise sheet you are asked to set up some infrastructure for developing C++ applications.
The time required for this exercise sheet varies depending on how much experience you have with installing software and setting up build environments.
If you run into problems consult your fellow students first and contact me if the problem persists.
## Task 1 (2 Points)
Install G++ and Clang, then compile the provided file `hello.cpp`.
Be sure to install a version that supports C++17.
Use the following flags when compiling:
-std=c++17 -Wall -Wextra -O2
If you are a Windows user, you may instead use the Visual Studio compiler.
Adjust the compile flags accordingly.
Alternatively, use [WSL]( instead.
Next, set up [Boost]( on your system and compile the provided file `hello_boost.cpp`.
Boost is quite common and provides you a set of useful C++ libraries.
Some of its content is even promoted into the C++ standard library.
## Task 2 (2 Points)
Run Clang on the provided file `vec.cpp` using the following command:
clang -std=c++17 -Xclang -ast-dump -fsyntax-only -Wno-vexing-parse vec.cpp
Clang will parse the input file and display its abstract syntax tree (AST).
In the bottom half of the output you'll find the function declaration of `main` followed by its `CompoundStmt`.
Take a close look at its children and compare the resulting AST with the input code.
Notice any oddities – something that looks counter intuitive?
Sometimes looking at the AST of a C++ program helps to understand what is really going on behind the scenes.
Clang is a useful tool for this purpose.
G++ also provides some mechanisms to dump internal representations, but I find Clang's AST more accessible.
As you can see, there are multiple different ways of initialisation in C++.
Check out the [corresponding section at cppreference](
## Task 3 (3 Points)
The directory `task3` hosts four subdirectories, `libFoo`, `libBar`, `libBaz`, and `app`.
Each folder prefixed with `lib` represents a shared library and contains a header and source file.
Furthermore, the library `` depends on ``.
`app` contains a single source file providing a `main` function.
It depends on all three libraries.
![Dependency Graph](images/task3_dependencies.png)
- model this project structure using [CMake](
- be sure to set the C++ standard to C++17 and enable warnings (`-Wall -Wextra`)
- the default build type should be *Release*
CMake itself is a build system generator.
You can choose from a variety of target build systems.
- use `cmake` to generate the actual build system
- build the project
Take note of the following features:
- *out of source build*, generated files do not pollute the source directory
- dependencies of translation-units are automatically obtained
What else do you notice?
## Task 4 (Required)
Send me a mail with your team composition, and your side project specification if you chose to do a custom side project.
Please use the following subject
703807 - Team Composition / Side Project
📧 [or this link](
## Additional Resources
- [Compiler Explorer](
- [Voltron – debugger UI toolkit](
- 🎥 [CppCon 2018 – *Simplicity: Not Just For Beginners*](
digraph {
node [shape=box style=filled fillcolor=lightblue fontname="Roboto Mono" fontsize=12 ];
edge [style=dashed arrowhead=onormal];
foo [label=""];
bar [label=""];
baz [label=""];
app -> foo;
app -> bar;
app -> baz;
baz -> bar;
#include <iostream>
int main()
std::cout << "Hello World" << std::endl;
#include <iostream>
#include <boost/algorithm/string/replace.hpp>
int main()
std::string s = "foo bar";
boost::replace_all(s, "foo", "Hello");
boost::replace_all(s, "bar", "World");
std::cout << s << std::endl;
class Vec3 {
Vec3() = default;
Vec3(int x, int y, int z) : x(x), y(y), z(z) {}
int x = 0;
int y = 0;
int z = 0;
int main()
Vec3 v0;
Vec3 v1();
Vec3 v2(1, 2, 3);
Vec3 v3{1, 2, 3};
Vec3 v4 = {1, 2, 3};
auto v5 = Vec3{};
auto v6 = Vec3(1, 2, 3);
auto v7 = Vec3{1, 2, 3};
#include "bar.hpp"
#include "baz.hpp"
#include "foo.hpp"
int main()
#include "bar.hpp"
#include <iostream>
void bar()
std::cout << "Function bar called" << std::endl;
#ifndef UIBK_703807_EX01_TASK3_BAR_HPP
#define UIBK_703807_EX01_TASK3_BAR_HPP
void bar();
#endif // UIBK_703807_EX01_TASK3_BAR_HPP
#include "baz.hpp"
#include <iostream>
#include "bar.hpp"
void baz()
std::cout << "Function baz called" << std::endl;
#ifndef UIBK_703807_EX01_TASK3_BAZ_HPP
#define UIBK_703807_EX01_TASK3_BAZ_HPP
void baz();
#endif // UIBK_703807_EX01_TASK3_BAZ_HPP
#include "foo.hpp"
#include <iostream>
void foo()
std::cout << "Function foo called" << std::endl;
#ifndef UIBK_703807_EX01_TASK3_FOO_HPP
#define UIBK_703807_EX01_TASK3_FOO_HPP
void foo();
#endif // UIBK_703807_EX01_TASK3_FOO_HPP
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment