18
Thomas Corbat / Prof. Peter Sommerlad Rapperswil, 23.2.2018 HS2018 Department I - C Plus Plus Modern and Lucid C++ Advanced for Professional Programmers Part 0 - Introduction

Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Embed Size (px)

Citation preview

Page 1: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Thomas Corbat / Prof. Peter Sommerlad

Rapperswil, 23.2.2018

HS2018

Department I - C Plus Plus

Modern and Lucid C++ Advanced

for Professional Programmers

Part 0 - Introduction

Page 2: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Modul: C++ Advanced (M_CPlA)

4 Credits (2h Vorlesung / 2h Übungen pro Woche)

Testate

3 Abgaben (Zeitpunkt wird bei Bedarf noch angepasst)

Keine Note

Zulassungsbedingung für die Prüfung

Prüfung

120 Minuten

Open Book (Ausnahme alte Prüfungen oder Abschriften davon)

2

Page 3: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Administratives

Wiki: https://wiki.ifs.hsr.ch/CppAdvanced

Wichtig: https!

Austausch von nicht öffentlichen Inhalten über Skripte-Server:

https://skripte.hsr.ch/Informatik/Fachbereich/C++_Advanced/CplA/

\\hsr.ch\root\alg\skripte\Informatik\Fachbereich\C++_Advanced\CplA

Arbeitsumgebung (Vorläufig)

Aktueller Compiler (GCC 7.2.0+): Windows MinGW von https://sourceforge.net/projects/mingw-w64/

VM vom C++ Modul ist verfügbar – nicht aktualisiert

Cevelop (www.cevelop.com)

An Karfreitag kein Unterricht: 30.03.2018

3

Page 4: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Why C++ Advanced?

What is your motivation?

What are your expectations?

4

Page 5: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Topics

Short refresh of C++ topics

New Features in C++17

Move semantics and type deduction

Low level memory management

Compile-time C++

Multi-Threading / Memory Model

Advanced Libraries/Development

Handling Legacy C++

Maybe more

5

Page 6: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Exercises

Typical tasks known from C++

One specific exercise that will be part of several exercises

Bounded Buffer

Start with a simple std::array-based version that will be extended every week

Parts of it will be Testat

6

Page 7: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Cevelop 1.9.1 with Constificator and Ctylechecker

Get Cevelop

at https://www.cevelop.com/download

Install the additional plug-ins Constificator and Ctylechecker

Update site (already configured in Cevelop): https://www.cevelop.com/update/1.9.0

7

Page 8: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Const Placement in Cevelop

Unfortunately, there are still some bugs which prevent const placement to be considered for code

generation

ctrl + shift + a might do the trick

8

Page 9: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Why Place const Right of the Type? (1/2)

const int seems to be more intuitive since it is how you would say the type of ci and ic...

That's is probably the reason why it usually stands on the left

Let's have a look at pointers

We read pointers from the declarator (i.e. right-to-left)

9

int i;const int ci;int const ic;

ci and ic have type

"const int"

int * ip;const int * cip;int const * icp;int * const ipc;const int * const cipc;int const * const icpc;

cicp and icpc have type "const pointer to const int"

Page 10: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Why Place const Right of the Type? (2/2)

Do ca and ac have the same type?

Yes, what is the type?

int * const

It is not only for reading consistency but also for semantic consistency!

10

using alias = int *;

const alias ca;alias const ac;

const applies to its left neighbor; only if there is no left neighbor it applies to its right neighbor

int const * const

const int * cip;int * const ipc;

?

Page 11: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Confusing Mix of mutable and const

The mutable specifier refers to the declared name

What does the following mean?

const makes the pointee int immutable

mutable makes the pointer mutable

When does this make sense? Shouldn't the non-const mutable_const_int_pointer always be

mutable?

11

mutable const int * mutable_const_int_pointer;

Page 12: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Features of Cevelop (Constificator)

Constificator

If activated

Makes suggestions about missing const qualifiers

12

Page 13: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

What does Ctylechecker do?

It annoys you in the first place!

When you have multiple ASSERTs in your test cases

When you use std::cin/std::cout outside of the main function

When there are issues with your include guard

13

Hey Apple!

Page 14: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

What does Ctylechecker do?

and reports...

... global non-const variables

... missing includes of Standard Library headers and provides a resolution!

... unused includes of Standard Library headers

14

Page 15: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

15(New) Features of Cevelop (Templator/Includator)

Template Instance Visualization

New version coming soon

Include Organization

15

Page 16: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

16Cevelop 1.9.0 New Project Wizard

Eclipse CDT 9.4 features a new wizard page

for creating new projects

With "C++ Managed Build" you can get to the

familiar wizard

16

Page 17: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

17Configure Cevelop for C++17 (Cevelop <= 1.9.0) 17

Page 18: Modern and Lucid C++ Advanced for Professional Programmers ... · Modul: C++ Advanced (M_CPlA) 4 Credits (2h Vorlesung / 2h Übungen pro Woche) Testate 3 Abgaben (Zeitpunkt wird bei

Resilience Required

You might encounter several bugs in Cevelop and its plug-ins (more than in CPl)

We are using modern and sophisticated features of C++17, which are not completely supported yet

When in doubt ask your compiler

When in more doubt ask several compilers

http://melpon.org/wandbox

https://gcc.godbolt.org/

18