C++ is a remarkably powerful systems-programming language, combining multiple programming paradigms – Procedural, Object Oriented and Generic – with a small, highly-efficient run-time environment. This makes it a strong candidate for building complex high-performance embedded systems.
The C++11 standard marked a fundamental change to the C++ language, introducing new idioms and more effective ways to build systems. This new style of programming is referred to as ‘Modern C++’.
This practical, hands-on course introduces the C++ language for use on hosted (Linux), multi-threaded embedded systems.
The focus is on developing effective, maintainable and efficient C++ programs. The course covers C++11, C++14 and C++17 and where relevant refers to C++20.
Overview:
A five-day course that provides a practical overview of Modern C++, focusing on developing object-oriented programs in a hosted, real-time environment. The course covers the current release of the C++ standard, known as C++14.
Course Objectives:
- To provide a solid understanding of the essentials of the C++ programming language.
- To give you practical experience of writing Modern C++ for Linux-based embedded applications.
- To give you the confidence to apply these new concepts to your next project.
Delegates will learn:
- Modern C++ syntax and semantics and idioms
- The Application Binary Interface (ABI) and memory model of C++
- Idioms and patterns for building effective C++ programs
- Real-time and concurrency design issues
Pre-requisites:
- A strong working knowledge of C
- Embedded development skills are useful, but not essential
Who should attend:
This course is aimed at C programmers working in a Linux environment who are moving to C++ for their embedded development.
Duration:
Five days.
Course Materials:
- Delegate manual
- Delegate workbook
- Delegate datakey
Course Workshop:
Attendees perform hands-on programming during course practicals. Approximately 50% of the course is given over to practical work. Students will be working in a Linux environment.
Program structure
- Hello World!
- The C++ build process
Stream I/O
- Stream objects
- Stream modifiers
The C++ object model
- Scalar types
- automatic type-deduction
- Brace initialisation syntax
- Scope and lifetime
- The C++ memory model
Constants
- constexpr objects
- constexpr functions
- static assert
- enum classes
Structures and tuples
- Structure alignment, padding and packing
- std::pair
- std::tuple
- Using tuples for multiple return values
Arrays
- Problems with C arrays
- std::array
- STL algorithms
- Iterators
- Range-for
Functions
- Function call ABIs
- References
- In, Out and In-Out parameters
- Named Return Value optimisation
Structuring code
- Header files
- Include guards
- Linking to C code
Namespaces
- Problems with organising large code bases
- Namespaces
- Namespace resolution issues
Introduction to Object Oriented Design
- Modularisation
- Coupling, Cohesion, Encapsulation and Abstraction
- Object-based design concepts
- The client-server model
User-defined types
- Classes
- Attributes and operations
- Member functions and the ‘this’ pointer
Initialising objects
- Non-static data member initialisers
- Constructors and destructors
- Delegating constructors
- Arrays of user-defined types
Objects and functions
- Converting constructors
- The explicit keyword
- const member functions
- Copy elision
Static
- Static member variables
- Static member functions
Building complex objects
- Composition
- Nested object construction
Connecting objects
- One-to-one association
- Bi-directional association
- friend functions
- Forward references
Creating Substitutable Objects
- Specialisation and inheritance
- Substitution
- Derived classes
- Virtual functions
Abstract Base Classes
- The Single Responsibility Principle
- Pure virtual functions
- Extending class interfaces
- dynamic_cast and its cost
Realising Interfaces
- The Dependency Inversion Principle
- Interfaces as design constructs
- Pure virtual classes
- Multiple inheritance of Interfaces
- Cross-casting
Dynamic objects
- new and delete
- std::unique_ptr
- std::shared_ptr
- std::weak_ptr
Sequence containers
- std::vector
- std::list
Associative containers
- std:::set
- std::unordered map
Callable objects
- Functors
- Lambda expressions
- Callable objects
- std::function
Principles of concurrency
- Concurrency vs Parallelism
- Simulating parallelism
- Scheduling methodologies
Threading
- Creating threads
- Joining and detaching threads
- Accessing the underlying OS
Mutual exclusion
- Race conditions
- Mutexes
- The Scope-locked Idiom
Thread synchronisation
- Condition variables
- The Guarded Suspension pattern
Asynchronous tasks
- Deferred synchronous calls
- Promises and futures
- Packaged tasks
- std::async()