Prompting C++ for Systems Engineering book cover by Vivek Bhadra
Published book · AVA

Prompting C++ for Systems Engineering

Learn modern C++ through practical systems-engineering examples, professional development tools, real-world projects, and responsible AI-assisted programming — a structured journey from fundamentals to object-oriented programming, memory management, templates, the STL, multithreading, debugging, testing, refactoring, and prompt engineering for C++ developers.

Author
Vivek Bhadra
Publisher
AVA
Format
Paperback and eBook
Language
English

Availability, format and pricing may differ between Amazon regions. Please select the store most appropriate for your location.

What’s inside

This practical C++ book combines core language knowledge with real-world development techniques, professional debugging and testing tools, hands-on projects, and critical guidance on using AI tools such as GitHub Copilot and ChatGPT responsibly. Tools covered throughout the book:

GitHub Copilot ChatGPT GDB Valgrind cppcheck clang-tidy GoogleTest GoogleMock Git Vim Visual Studio Code

Full table of contents

Explore the complete chapter-by-chapter contents. The book progresses from C++ fundamentals and development-environment setup to object-oriented programming, memory management, templates, the Standard Template Library, multithreading, debugging, testing, refactoring, and responsible AI-assisted software development.

CH 01Getting Started With C++ and AI Tools
  • Introduction
  • Structure
  • Risks of Using AI in C++ Development
    • Benefits and Responsible Use of AI Tools
    • Striking the Balance: Using AI as an Ally, Not a Crutch
  • Setting up the Development Environment
    • Compiler and Build System
      • macOS (Using Homebrew)
      • Windows (MinGW and CMake)
  • Visual Studio Code + GitHub Copilot
    • Installing VS Code on Ubuntu 22.04
    • Step 1: Prepare Your System
    • Step 2: Import Microsoft’s GPG Key
    • Step 3: Add the VS Code Repository
    • Step 4: Update and Install VS Code
    • Setting up GitHub Copilot
    • For Existing GitHub Users
    • Troubleshooting: Copilot Setup Stuck on “Getting Copilot Ready…”
    • Restart and Retry
    • Other Troubleshooting Steps
    • New to GitHub? Create an Account First
  • Introducing AI Tools for Development
    • GitHub Copilot
    • ChatGPT (OpenAI)
    • Amazon Q Developer
    • Installing the C/C++ Extension Manually in VS Code
  • Writing Your First C++ Program
    • Prerequisites
    • Create Your Project
      • Understanding a Project in VS Code
    • Creating a C++ File
    • Compiling and Running
      • Method 1: Compiling Using the Command Line
      • Method 2: Compile and Run from inside VS Code
    • Sample Output
    • Sample task.json
    • Setting up Clang-Format in VSCode
      • Step 1: Install the Clang-Format Extension in VS Code
      • Step 2: Install Clang-Format on Your System
      • Step 3: Add the Formatting Configuration File
      • Step 4: Enable Clang-Format in the Project Workspace
      • Step 5: Test the Setup
  • Generating the Same Code with AI Tools
    • Using GitHub Copilot in VS Code
      • Early Observations with GitHub Copilot
    • Using ChatGPT outside VS Code
      • Getting Started with ChatGPT
      • Early Observations with ChatGPT
  • Reflection: Human versus AI – A First Look
  • Best Practices Moving Forward
  • Conclusion
CH 02Understanding C++ Basics
  • Introduction
  • Structure
  • Primitive Data Types and Modifiers in C++
    • Size of Primitive Data Types
    • Fixed-Width Integer Types
  • Type Modifiers and Qualifiers
    • Type Modifiers
    • Type Qualifiers
      • The const Type Qualifier
      • The Volatile Type Qualifier
      • Implications of Omitting the Volatile Qualifier
      • Effect of Applying the Volatile Qualifier
  • Storage Class Specifiers in C++
    • Auto
    • Static
    • Extern
  • Variable Declaration and Definition
    • Declaration
    • Definition
  • Variable Initialization Styles
    • Copy Initialization
      • Narrowing Conversions
    • Direct Initialization
    • Uniform Initialization (Brace Initialization)
    • Comparing C++ Initialization Methods
  • Type Conversions and Compiler Warnings
    • Prompting AI for Insight
  • Memory Layout: Stack versus Heap
    • Stack Memory
    • Understanding Stack Overflow
      • Deep or Infinite Recursion
      • Large Local Allocations
      • The Reason behind Stack Size Limitations
      • How to Avoid Stack Overflow
    • Heap Memory
      • Understanding Memory Leaks
      • Stack versus Heap Memory in Action
  • Variable Scope and Lifetime
    • Local Scope
    • Global Scope
      • Understanding the Translation Unit
  • Compilation Pipeline: Source to Executable
    • Overview of the Pipeline
    • Preprocessing
    • Compilation
    • Assembling
    • Linking
    • Case Study: Resolving a Linker Error
    • Using AI Tools for Compilation Insights
  • AI-Assisted Debugging
    • Overview of AI-Assisted Debugging
    • Interpreting Compiler Errors with AI
    • Resolving Syntax Errors with AI
    • Diagnosing Linker Errors with AI
    • Case Study: Debugging with AI
    • Crafting Effective AI Prompts
  • Mini-Project: Memory Explorer
    • Overview of the Memory Explorer
      • Implementation
      • Using ChatGPT to Understand the Program
    • Case Study: Optimizing Variable Types
    • Extending the Memory Explorer
  • Conclusion
CH 03Control Flow and Logical Thinking
  • Introduction
  • Structure
  • Conditional Statements
    • The if Statement
    • The if-else and else-if
    • Relational Operators
    • Logical Operators in Conditions
      • Logical Operators in C++
      • Understanding the Compound Logical Expression
      • Short-Circuit Evaluation
      • Common Pitfalls
    • The switch Statement
      • Syntax and Usage
      • Best Practice: Use a Break to Prevent Fall-through
      • Intentional Fall-through
      • Making Intentional Fall-through Explicit with [[fallthrough]]
    • AI-Assisted Learning
      • Generating Conditional Logic Using ChatGPT Prompt
      • Generating Conditional Logic Using Copilot in VS Code
      • Sample Copilot Output
      • Prompting Copilot to Create a Switch-Case Menu
      • Observations and Improvements
      • Prompting ChatGPT to Generate a Switch-Case Menu
  • Loops and Iteration
    • The for Loop
    • The while Loop
    • The do-while Loop
    • Breaking and Continuing Loops
      • The break Statement
      • The continue Statement
      • Prompting ChatGPT to Practice Break and Continue
    • Avoiding Common Pitfalls in Loop Control
      • Infinite Loops
      • Off-by-One Errors
  • Visualizing Code Flow
    • Visualizing Code Execution with Dry Run Tables
    • Visualizing Code Flow with Flowcharts
      • Benefits of Using Flowcharts
      • Common Flowchart Symbols
      • From Code to Flowchart
  • Case Study: Human versus AI: A Number Guessing Game
    • Human Approach: Designing Step-by-Step
    • AI Approach
      • Generating Code with GitHub Copilot
    • AI Take Away
  • Conclusion
CH 04Functions, Scope, and Modularization
  • Introduction
  • Structure
  • Function Declaration, Definition, and Invocation
    • Parts of a Function
    • Function Forward Declaration
    • Syntax of a Forward Declaration
    • Difference between Definition and Declaration
    • Function Declarations in Header Files
    • Using Include Guards in Header Files
    • Compiling and Running the Multi-File C++ Project in VS Code
    • Purpose of Function Declarations
    • Function Definition
    • Function Invocation
  • Using Function Return Values Effectively
    • Basic Usage of Return Values
    • Enforcing Attention to Return Values with [[nodiscard]]
  • Parameter Passing: By Value, by Reference, by Pointer
    • Pass by Value
    • Pass by Reference
      • Mechanism of Pass-by-Reference
    • Pass by Pointer
    • Comparison
    • Array-to-Pointer Decay in Function Parameters
    • Best Practice
  • Function Overloading and Default Arguments
    • Function Overloading
      • Function Overloading and Function Arguments
      • Name Mangling in Function Overloading
      • Function Overloading and Polymorphism
    • Default Arguments
      • Best Practice
  • Inline Functions and Recursion
    • Inline Functions
      • Function Call Overhead
    • Recursion
  • Stack Frame Behavior and Call Tracing
    • Prerequisites
    • Example Debug Session: Stack Frame Trace
  • Code Modularity and Logical Decomposition
    • Non-Modular Approach
    • Modular Approach
  • Understanding Recursive Functions Using AI
    • How AI Tools Can Help
  • Project: Menu-Driven Unit Converter
    • Project Requirements
    • Explanation of the Unit Converter Program
  • Using AI Tools to Analyze, Refactor, and Debug the Code
    • Analyzing and Refactoring Code with AI Tools
  • Conclusion
CH 05Arrays, Strings, and STL Vectors
  • Introduction
  • Structure
  • Understanding C-Style Arrays
    • Memory Layout
  • Concept of Arrays and Indexing
    • Declaring, Initializing, and Using Arrays
      • Syntax to Declare an Array
      • Initializing an Array
      • Accessing Array Elements
    • Default Initialization of Arrays
    • Exploring Memory Layout with GitHub Copilot
      • Steps to Try This in VS Code
      • Sample Output: Copilot-Generated C++ Program
      • Compiling and Running the Program
    • Data Types, Memory Layout, and Array Indexing
    • Traversing and Manipulating Arrays
  • C-Style Null-Terminated Strings in C++
    • Declaration and Initialization
    • Element-wise Initialization
    • Initialization Using String Literal
    • Initialization Using a Brace-Initializer List
    • Difference between Initialization Styles
    • Traversing a C-Style String
    • Traversing a C-Style String Using strlen
  • String Literals in C++
    • Understanding the Data Type of String Literals
      • Visual Verification
  • C++-Style std::array
    • Declaration and Initialization
    • Key Features
    • Accessing Elements
      • Access Using the Subscript Operator ([])
      • Access Using the .at() Member Function
    • Determining the Number of Elements: .size()
    • Traversal of an std::array
  • Transitioning from Fixed Arrays to std::string
  • Modern C++ Strings: std::string
    • Limitations of C-style Strings
    • Advantages of std::string over C-style Strings
    • Declaration and Initialization
    • Key Operations on std::string
  • From Fixed-Size Arrays to Resizable Arrays
    • Key Features of std::vector
    • Declaring and Using std::vector
      • General Declaration Syntax
      • Initializing std::vector
    • Adding Elements Dynamically
      • Using push_back()
      • Using emplace_back()
      • Difference between emplace_back() and push_back()
      • Best Practice
    • Traversing a std::vector
      • Traditional for Loop with Indexing
      • Range-Based for Loop
    • Modifying and Removing Elements
      • Removing Elements from a Vector
    • Managing Capacity and Size
      • .size() versus .capacity()
      • Reserving Capacity in Advance
      • Resizing a Vector
  • Detecting and Debugging Errors
    • Out-of-Bounds Access
    • Segmentation Fault
    • Safe Access with .at()
    • Debugging Tip: Visualize Errors with Online Tools
    • Using AI Tools to Prevent Segmentation Faults and Out-of-Bounds Access
  • Using AI Tools to Generate a Multi-Container Stats Visualizer
    • Human Review and Takeaways
      • Guidelines for Using AI Tools Effectively
    • Prompting AI Tools to Match Your Learning Level
      • Guide AI with Effective Prompts
      • Example Revised Prompt for Copilot
  • Conclusion
CH 06Object-Oriented Programming in C++ with AI Assistance
  • Introduction
    • Structure
    • Introduction to Classes, Objects, and Member Functions
    • Basic Syntax of a Class Declaration
    • Designing a Simple Class
    • Designing the Class Using Struct Construct
    • Instantiating a Class
    • Syntax for Creating an Object
  • Understanding Data Encapsulation
    • Understanding Public and Private Access
    • Accessing Class Data: Dot Operator versus Public Methods
    • Hiding Data via the Private Section
    • Keeping Internal Data Hidden from Program Logic
  • Encapsulation Mechanisms and Rules
    • Access Control in Classes
  • Constructors, Destructors, and Object Lifecycle
    • Constructor
      • Member Initializer List
      • Order of Initialization
      • Inline Initialization
    • Destructor
    • Object Lifecycle
  • Copy Constructor and Copy Assignment Operator
    • Copy Constructor
      • Object Initialization
      • Passing Objects by Value to Functions
      • Returning Objects by Value from Functions
      • Copy Elision
    • Copy Assignment Operator
    • Difference between Copy Constructor and Assignment Operator
    • Canonical Form of a Copy Assignment Operator
  • Defaulted and Deleted Special Members
    • Using Default to Request Compiler-Generated Behavior
    • Using Delete to Forbid Certain Operations
  • The Rule of Three
  • Type Conversions and the explicit Keyword
    • The Implicit Conversion
    • Using Explicit to Prevent Implicit Conversion
  • Static and Non-Static Members
    • Static Member Function
  • Defining Member Functions outside the Class
  • Creating and Using a Static Library in C++
    • Build the Static Library
    • Customer App Integration
  • Const Member Functions and Mutable Members
    • The Mutable Keyword
  • Operator Overloading
  • Inheritance
  • AI-Generated Class Scaffolds and Design Comparison
    • A Prompt to the AI (Copilot)
    • Analysis of the AI-Generated Code
  • Mini-Project: Zoo Management Simulator Using OOP
    • Implement the Animal Behaviors
  • Conclusion
CH 07Pointers and Memory Management
  • Introduction
  • Structure
  • Pointer Basics: Declaration, Dereferencing, and Types
    • General Pointer Declaration Syntax
    • Pointer Dereferencing
    • Pointer Types and Type Safety
  • Safe Initialization and nullptr
  • Pointers and Arrays
    • Array Name and Pointer Decay
    • The sizeof Difference
    • Passing Arrays to Functions
  • Pointer Arithmetic
    • Pointer Arithmetic with Arrays
  • Dynamic Memory Management
    • Array Allocation and Deallocation Using new[] and delete[]
    • Allocation and Deallocation of User-Defined Types
      • Member Access through Pointers: The Arrow Operator
    • Problem with Manual Memory Management
      • Dangling Pointers
  • RAII (Resource Acquisition Is Initialization)
    • C++’s Guarantee: Destructors Always Run on Scope Exit
      • RAII in Action
      • RAII Solves the Problem
  • Smart Pointers: RAII in Practice
    • Understanding Class Templates in C++
    • Types of Smart Pointers
      • Unique Pointer
      • Creating, Initializing, and Using unique_ptr
      • Using std::make_unique
      • The Auto Keyword
      • Shared Pointer
      • Creating, Initializing, and Using shared_ptr
      • Using std::make_shared
      • Single Allocation Efficiency
      • std::shared_ptr: Pass by Value versus Const Reference
      • Weak Pointer
      • The Purpose of weak_ptr
      • The Cyclic Reference Problem
      • Creating, Initializing, and Using weak_ptr
      • Declaring a weak_ptr
      • Initialization from an Existing shared_ptr
      • Accessing a weak_ptr
      • Checking Object Validity with Expired()
      • Recommended Pattern for Accessing a std::weak_ptr
  • Releasing and Replacing Ownership
  • Accessing the Raw Pointer with get()
  • Using AI Tools to Generate and Debug Pointer-Based Code
    • How Copilot Helps with Pointers
    • Debugging with Prompts
  • Conclusion
CH 08Inheritance and Polymorphism
  • Introduction
  • Structure
  • Inheritance Basics: Base and Derived Classes
    • Base Class
  • Derived Class
    • Minimize Code Changes, Reduce Bugs
    • Access Specifier: Private versus Protected
    • Minimize Access to Maximize Data Encapsulation
    • Understanding the Inheritance in Savings Account
    • Representing Inheritance with UML
  • Access Control in Inheritance
    • Public Inheritance
    • Protected Inheritance
    • Private Inheritance
  • Name Hiding or Shadowing
  • Derived Class Object Accessing Base Class Members
    • Scope Resolution Operator
  • From Compile-Time Resolution to Runtime Behavior
    • Base Class Pointer Can Point to a Derived Class Object
    • Virtual Function and Dynamic Dispatch
    • Polymorphism
    • Pure Virtual Functions and Abstract Classes
  • Putting It All Together
    • The Shape Hierarchy
    • Defining Inherited Concrete Shapes
    • Managing Objects via Smart Pointers and Containers
    • Generic Algorithms and Polymorphism
    • Dynamic Dispatch in Action
    • Importance of the Override Keyword
    • Virtual Destructors
    • The Final Specifier
  • Object Slicing
  • The Diamond Problem
    • Virtual Inheritance
  • AI-Assisted Mini Project: Smart Home Device Control System
    • Project Brief
    • File Structure
    • Smart Home Device Control System
      • Prompts for Copilot to Generate Source Code
  • Conclusion
CH 09Templates and Exceptions
  • Introduction
  • Structure
  • Motivation for Templates: Reducing Code Duplication
    • Advantages of Using Templates
  • Function Templates
    • Calling Function Templates
  • Class Templates
  • Template Instantiation
  • Compile-Time Type Checking in Templates
  • Template Specialization
    • Full Specialization
    • Partial Specialization
  • Exception Handling in C++
    • Exception Handling by Example
    • Multiple Exception Types
    • Catch-All Handlers
  • The C++ Exception Class
    • The Exception Hierarchy in C++
      • Logic Errors
      • Runtime Errors
  • Catch Block Hierarchy
  • Rethrowing Exceptions
  • std::terminate and Program Termination
  • Stack Unwinding during Exception Handling
  • Destructors Must Not Throw
  • Exception Safety and RAII
  • noexcept and Exception Specifications in Modern C++
  • Best Practices and Common Pitfalls
  • AI-Assisted Mini Project: Generic Data Processing with Exception Handling
    • Code Walk through
    • Analysis
  • Conclusion
CH 10Standard Template Library and Generic Programming
  • Introduction
  • Structure
  • Introduction to the STL and Its Role in Modern C++
  • Containers
    • std::vector: The Dynamic Array
      • Declaring and Initializing a Vector
      • Adding New Data
      • Removing Data
      • Introducing Iterators in Containers
      • Accessing Vector Elements
      • Traversing a Vector
    • std::list: The Doubly Linked List
      • Declaring and Initializing a List
      • Adding and Removing Data
      • Erasing Element
      • Accessing and Traversing Elements
      • When to Use std::list
    • std::map: The Ordered Key-Value Store
      • Declaring and Initializing a Map
      • Alternative Ways to Initialize STL Map
      • Custom Ordering in std::map
      • Adding Elements to the Map
      • Removing Elements from Map
      • Accessing Elements
      • Traversing a Map
      • Searching for Elements
    • std::multimap: Handling Duplicate Keys
      • Searching Elements in Multimap
    • std::unordered_map: The Hash-Based Key-Value Store
    • Trade-offs between Map and unordered_map
    • std::set: The Ordered Unique Collection
      • Declaring and Initializing a Set
      • Adding Elements
      • Removing Elements
      • Accessing and Traversing Elements
      • Searching for Elements
      • Summary of Common Set Operations
      • When to Use std::set
  • Performance Considerations in STL Containers
    • Contiguous Containers: std::vector
    • Linked Containers: std::list
    • Associative Containers: std::map and std::set
    • Unordered Containers: std::unordered_map
    • Choosing the Right Container
  • Overview of STL Algorithms
    • std::sort: Sorting Elements
    • std::find: Searching for a Specific Value
    • std::find_if: Searching by Condition
    • std::transform: Applying an Operation to Each Element
    • std::for_each: Performing an Action on Each Element
    • std::lower_bound, std::upper_bound: Fast Positions in Sorted Data
    • Summary
  • AI-Assisted Mini-Project
    • Implementing an LRU Cache Using STL Containers with GitHub Copilot
      • Project Goal
      • Working in VS Code with Copilot (Agent Mode)
      • Create the Base Implementation
      • Convert It into a Class Template
      • Refine the Interface for Safety and Correctness
      • Improve Const-Correctness and Exception Safety
      • Understanding the Final Implementation
  • Conclusion
CH 11Functors, Lambdas, and Move Semantics
  • Introduction
  • Structure
  • Function Objects (Functors)
    • Functors: Functions with Memory
    • Stateful versus Stateless Functors
    • Reusability and Encapsulation
    • Functors and STL Algorithms
  • Lambda Expressions
    • The Need for Inline Flexibility
    • Basic Lambda Syntax and Structure
    • Lambdas as Compiler-Generated Functors
  • Closures: Capturing Context
    • Understanding Lambda Captures
    • Dangling References
    • A Real-World Example: IoT Sensor Monitoring
  • Lambdas and STL Algorithms
    • Lambda for Clarity in STL Algorithms
    • Using Lambdas to Customize STL Algorithm Behavior
  • Understanding Move Semantics
    • Temporaries in C++
      • Function Return Values
      • Implicit Conversions
      • Expression Results
    • lvalues and rvalues
    • lvalue and rvalue References
    • Temporaries and Reference Binding
    • Move Constructors and Move Assignment Operators
      • Move Constructor
      • Move Assignment Operator
    • Practical Usage of std::move and std::forward
  • AI-Assisted Mini-Project
  • Project Overview
  • Setting up
  • Working Hand in Hand with Copilot
    • Prompt 1: Designing the Move-Only Data Container
    • Prompt 2: Add Human-Readable Output
    • Prompt 3: Add Calibration Functor
    • Prompt 4: Add Lambda Filter
    • Prompt 5: Build the Full Processing Pipeline
    • Prompt 6: Demonstrate the Pipeline with main()
    • Prompt 7: AI Code Review and Final Polish
    • Compiling the Project from the Command Line
    • Compiling and Running the Modified Code
    • Identifying the Erroneous Output
    • Analyzing the Bug
    • Fixing the Bug
  • Conclusion
CH 12Multithreading and Concurrency Basics
  • Introduction
  • Structure
  • Introduction to Concurrency
    • Concurrency versus Parallelism
      • Understanding Parallelism
      • Pseudo-Parallelism on a Single Core
      • A Simple Analogy
      • Concurrency as Design, Parallelism as Execution
  • Processes and Threads
    • Processes: Independent Execution Units
    • Threads: Lightweight Execution Paths
  • Thread Creation and Lifecycle Management
    • Creating a Thread
    • Joining a Thread
    • Detaching a Thread
  • RAII-Based Thread Management
    • Use of joinable() for Safe Thread Cleanup
    • Transitioning to Standard RAII Threads in C++20
      • Native RAII Implementation in std::jthread
      • Standardized Cooperative Interruption
  • Returning Results from Threads
    • Setting up the Two One-Way Channels
    • Spawning the Worker and Transferring Ownership
    • What the Worker Thread Does
    • The Main Thread Sends the Input
    • The Main Thread Waits for the Result
  • Asynchronous Task Execution with std::async
    • Understanding Launch Policies
  • Sharing Data and Synchronization
    • Race Condition
    • Mutual Exclusion with Mutexes
    • RAII-Based Lock Management Using std::lock_guard
    • std::unique_lock: Flexible Locking
    • std::shared_mutex: Reader-Writer Locking
  • Waiting for Events: Condition Variables
    • Using notify_all()
  • Atomic Operations
    • Memory Ordering in Atomic Operations
  • AI-Assisted Mini-Project: Building a Thread-Safe Queue
    • Project Context
    • Step 1: Generating the Boilerplate with Copilot
    • AI Code Review
      • Missing Shutdown Mechanism
      • Unsafe Waiting Behavior
      • Return Type Limitation
      • Thread-Safety of Observers
      • Naming Consistency
      • Simplifying the Main Function
  • Conclusion
CH 13Debugging, Testing, and Refactoring with AI Tools
  • Introduction
  • Structure
  • Fundamentals of Debugging in C++
    • Compile with Debug Information
    • Introducing Makefile
      • Role of Makefiles in Debugging
      • Debug Build and Release Build
      • Dependency Management and Incremental Rebuilds
      • Consistency and Reproducibility
      • Transparency and Debugging Knowledge
      • Build Tools Overview and Key Terms
  • Enabling Debug Information
    • Running without Debug Information
    • Including Debug Information via Makefile
      • Makefile Example
    • Running with Debug Information
  • Debugging with GDB
    • Installing GDB (GNU Debugger)
    • Example Program
      • Logic Error
      • Compiling the Program
    • Stepping through Code with GDB
      • Attaching GDB to the Executable
      • Setting a Breakpoint in GDB
  • Essential GDB Commands
    • Useful Notes about GDB
  • Analyzing Core Dump Using GDB
    • Prerequisites: Generating a Core Dump
    • Example Program
    • Compile the Program
    • Run the Program and Trigger the Crash
    • Locate the Core File
      • Troubleshooting
    • Load the Core File in GDB
    • Inspect the Backtrace
    • Inspect Variables at the Point of Failure
    • Moving to the Relevant Stack Frame
    • Inspecting the Data That Caused the Crash
    • Identifying the Issue and Applying the Fix
  • Debugging by Strace
    • Useful Strace Options
    • Running with strace
    • Understanding the Strace Output
  • Debugging with Valgrind
    • How Valgrind Works
      • Performance Overhead
    • Running a C++ Program under Valgrind
      • Debug Builds and Valgrind
      • Running with Valgrind
    • Understanding the Valgrind Output
      • Invalid Read
      • Location of the Invalid Read
      • Point at Which the Memory was Freed
      • Point at Which the Memory was Allocated
      • Heap Summary
      • Error Summary
    • Suppressions
      • Using Suppressions with the Current Example
      • Suppression Rule
  • Static Analysis with cppcheck
    • Installing cppcheck on Ubuntu
    • Running cppcheck on the Source Code
  • Compiler-Aware Static Analysis with Clang-tidy
    • Installing Clang-tidy on Ubuntu
    • Using Clang-tidy in Practice
    • Configuring Clang-tidy
    • Build and Analysis Support Using a Makefile
    • Interpreting the Diagnostic
  • Transitioning from Debugging to Testing
  • Unit Testing with GoogleTest
    • Setting up GoogleTest on Ubuntu
      • Installing the GoogleTest Source Package
      • Installing CMake
      • Compile the GoogleTest Libraries
      • Install the Compiled Libraries
  • Test-Driven Development Workflow
    • Writing Your First Test
      • Preparing the Workspace
      • Compiling the Program
      • Running the Program
      • Understanding the Test Output
  • Introduction to GoogleMock
    • Installing the Required Dependencies
    • Setting up the Example
    • Mocking What is Not Available
    • Implement the Test
    • Preparing the Build
    • Compiling and Running the Test
    • Understanding the Output
    • Purpose of GoogleMock Test
  • Introducing CI/CD
    • Importance of Continuous Testing in Modern Development
    • Integrating Debug Tools with GoogleMock Test
      • Preparing the Workspace
      • Understanding the Program
      • Representing a Missing Dependency
      • Creating a Mock Replacement
      • Code under Test
      • Setting up the Expectation
      • Demonstrating Debugging-Tool Integration
      • Integrating Debugging Tools via the Makefile
      • Understanding What the Makefile Does
      • Compiling and Running the Program
      • Laying the Groundwork for CI/CD Integration
  • AI-Assisted Testing
  • Refactoring Principles and Techniques
  • AI-Powered Refactoring
  • Conclusion
CH 14Debugging Strategies for C++ Engineers
  • Introduction
  • Structure
  • Building a Mental Model
    • Characterizing the Problem
    • Visualizing the Problem
  • Localize the Problem
  • Make an Action Plan
    • AI Assistance: Formalizing and Reviewing the Action Plan
  • Log Your Actions
    • AI Assistance: Structuring Investigation Records
  • Discuss with Colleagues
  • Debugging by Code Browsing
    • Code Inspection: Vim, cscope, and ctags on Linux
      • Installing Vim
      • Installing cscope
      • Installing ctags
      • Generating the cscope Database
      • Collecting Source and Header Files
      • Building the cscope Database File
      • Generating the ctags Database
      • Integrating cscope Databases with Vim
      • Setting the cscope Environment Variable
      • Recommended Persistent Vim Configuration
      • Structured Code Walkthrough in Vim
    • Browsing in Visual Studio Code
      • Setting up the Project for Inspection
      • Configuration for Accurate Navigation
      • Launching the Editor
      • Essential Code Navigation Shortcuts
  • Debugging by Searching
    • Targeted Recursive Search
      • Combining Multiple String Patterns in a Single Search
      • Excluding Directories from Recursive Searches
      • Targeting Specific Subsets
      • Excluding Binary Files from Searches
    • Inspecting Binaries with Strings Command
    • Combining Search Utilities
      • Restricting Searches by File Type
  • Debugging by Log Inspection
    • Using Log Viewers
      • AI Assistance: Summarizing Large Log Excerpts
    • Logs as a Temporal Narrative
      • Debugging through Trace Instrumentation
      • Building and Running the Example
  • Debugging through Historical Comparison
    • Binary Search over Releases
    • Using git bisect
  • Debugging through Version Control
    • Using git log
    • Using git show
      • Inspecting a Suspect Commit
    • Using git blame
  • Debugging through Visual Diff Tools
  • Conclusion
CH 15Prompt Engineering for C++ Developers
  • Introduction
  • Structure
  • The Structure of an Effective Prompt
    • Context: Define the Environment
      • The Weak Prompt Example
      • The Refined Prompt
      • Taking it Further: Iterative Refinement
    • Intent: State What You Need
    • Constraints: Set the Boundaries
    • Role: Define the Perspective
    • Output Structure: Specify the Format
  • Types of Prompts Used in C++ Development
    • Generation Prompts
      • Example: Generating a Thread-Safe Resource Manager
    • Explanation Prompts
    • Strategic Refactoring Prompts
    • Debugging Prompts
    • Optimization Prompts
  • Techniques for Constructing Prompts
    • Step-by-Step Prompting
    • Iterative Refinement
    • Chaining
  • Recognizing and Managing the Limitations of AI
    • Hallucination
    • Vagueness
    • Wrong Environment Assumptions
  • Prompting Anti-Patterns
    • Overconstraint
    • Mixed Tasks
    • Style Contradictions
  • Mini Project: Prompt Refinement for Behavior-Preserving Code Modernization
    • Objective
    • Original Implementation
    • Weak Prompt
    • Refined Prompt
    • Refactored Implementation
    • Validation and Analysis
    • Learning Outcome
  • Conclusion

Who this book is for

Prompting C++ for Systems Engineering is designed for students, software developers, embedded and systems engineers, interview candidates, and professionals who want to strengthen their knowledge of modern C++ and responsible AI-assisted software development.

No previous C++ experience is assumed, although familiarity with basic programming concepts will be helpful.

About the author

Vivek Bhadra is a published C++ author and Embedded Software Engineer with more than 24 years of professional experience in C++, embedded systems, real-time software, and low-level development. He has worked across industries including IoT, defence, EV charging, networking, consumer electronics, and marine technology.

Alongside his engineering career, he has mentored developers and provided structured C++ tuition to students, early-career engineers, experienced professionals, and technical-interview candidates.

Frequently asked questions

Is this book suitable for C++ beginners?

Yes. It begins with development-environment setup, fundamental data types, control flow, functions, arrays, strings, and object-oriented programming before progressing to advanced material.

Does the book cover modern C++?

Yes. It covers smart pointers, RAII, templates, STL containers and algorithms, lambdas, move semantics, concurrency, atomics, and std::jthread.

Does the book teach debugging and testing?

Yes. It covers GDB, Valgrind, strace, core dumps, cppcheck, clang-tidy, GoogleTest, GoogleMock, refactoring, and systematic debugging strategies.

How are AI tools used in the book?

The book demonstrates GitHub Copilot and ChatGPT while teaching readers to review generated code critically and identify hallucinations, vague prompts, and incorrect environment assumptions.

Where can I buy the book?

The book is available through Amazon UK, Amazon USA, and Amazon India using the regional links provided on this page.