Book Image

Hands-On System Programming with C++

By : Dr. Rian Quinn
Book Image

Hands-On System Programming with C++

By: Dr. Rian Quinn

Overview of this book

C++ is a general-purpose programming language with a bias toward system programming as it provides ready access to hardware-level resources, efficient compilation, and a versatile approach to higher-level abstractions. This book will help you understand the benefits of system programming with C++17. You will gain a firm understanding of various C, C++, and POSIX standards, as well as their respective system types for both C++ and POSIX. After a brief refresher on C++, Resource Acquisition Is Initialization (RAII), and the new C++ Guideline Support Library (GSL), you will learn to program Linux and Unix systems along with process management. As you progress through the chapters, you will become acquainted with C++'s support for IO. You will then study various memory management methods, including a chapter on allocators and how they benefit system programming. You will also explore how to program file input and output and learn about POSIX sockets. This book will help you get to grips with safely setting up a UDP and TCP server/client. Finally, you will be guided through Unix time interfaces, multithreading, and error handling with C++ exceptions. By the end of this book, you will be comfortable with using C++ to program high-quality systems.
Table of Contents (16 chapters)

What this book covers

Chapter 1, Getting Started with System Programming, lays the foundation for the book, helping to define what system programming is by providing some basic examples and explaining the benefits of system programming with C++.

Chapter 2, Learning the C, C++17, and POSIX Standards, reviews the C, C++, and POSIX standards, providing an overview of the facilities provided by each standard with respect to system programming, as well as a general overview of the topics that will be discussed throughout this book.

Chapter 3, System Types for C and C++, provides a comprehensive overview of the system types that are provided by C and C++ and how they are used when carrying out system programming. This chapter will also discuss many of the pitfalls associated with the native types and how to overcome them.

Chapter 4, C++, RAII, and the GSL Refresher, provides a general overview of the additions provided by C++17. This chapter will also discuss the benefits of Resource Acquisition Is Initialization (RAII), and how to leverage it when carrying out system programming. This chapter will conclude with an overview of the Guideline Support Library, which is used throughout this book to help maintain C++ core guideline compliance.

Chapter 5, Programming Linux/Unix Systems, provides a comprehensive overview of programming on Linux /UNIX-based systems, including an overview of the System V specification, programming Linux processes, and Linux-based signals.

Chapter 6, Learning to Program Console Input/Output, provides a complete overview of how to leverage C++ to program console input and output, including std::cout and std::cin. More advanced topics, such as how to handle custom types, will also be discussed.

Chapter 7, A Comprehensive Look at Memory Management, provides a complete review of the memory management facilities provided by both C and C++. In this chapter, we will review the shortcomings of C and how modern C++ can be used to overcome many of these shortcomings.

Chapter 8, Learning to Program File Input/Output, reviews how to read and write to files using C++17 and compare these facilities to those provided by C. In addition, we will dive into the std::filesystem additions provided by C++17 for working with files and directories on disk.

Chapter 9, A Hands-On Approach to Allocators, covers C++ allocators and how they can be leveraged to perform system programming. Unlike most other attempts at describing C++ allocators, we will walk you through how to create multiple, real-world examples of stateful allocators, including a memory pool allocator, and demonstrate its potential performance benefits.

Chapter 10, Programming POSIX Sockets Using C++, provides an overview of how to program POSIX sockets (in other words, network programming) using C++ with a series of examples. In this chapter, we will also discuss some of the issues associated with POSIX sockets and how they can be overcome.

Chapter 11, Time Interfaces in Unix, provides a thorough overview of the time interfaces provided by both C and C++ and how they can be used together to deal with time while system programming, including how to use the interface for benchmarking.

Chapter 12, Learning to Program POSIX and C++ Threads, discusses the thread programming and synchronization facilities provided by both POSIX and C++ and how they interrelate. We will also provide a series of examples that demonstrate how to leverage these facilities.

Chapter 13, Error - Handling with Exceptions, covers both C and C++ error handling, including C and C++ exceptions. In this chapter, we will also walk through a series of examples that demonstrate the benefits of leveraging C++ exceptions over traditional C error handling.