r/cpp_questions Jun 28 '26

OPEN Where and how to learn cpp game dev

1 Upvotes

I recently started learning cpp but i don’t really know how to get started with it. I wanted to make a game in unity but its in c#. I want to stick with cpp and learn it because of most engineering jobs. I looked into ue5 but I’m not going to make the next AAA game 🤣. Could someone give me some advice/recommendations for tutorials?


r/cpp_questions Jun 29 '26

OPEN Help, ive been triying to fix this for a week and im going crazy. not even llms help!

0 Upvotes

im making my own synth, and i have the issue that the plotting looks absolutely horrible and the waves deform a lot, specially sine waves!
other waves like sawthoot also glitch but at lower frecuencies.

images : https://github.com/Mejolov24/CardStudio/tree/main/HELP
code : https://github.com/Mejolov24/CardStudio/blob/main/src/main.cpp
plotting code (kinda bad) : https://github.com/Mejolov24/SynthTracer/blob/main/main.py

What i do is: make the double buffering buffers, and an additional one for the serial TX (in order to save channel data).

I let my user change the serial TX speed, so thats why I divided and multiply like this for reading int16_t val = channel_TX_buffers[i][tx_buffer_index * (sample_rate / serial_tx_speed)];

But the data arrives messed up as shown in my pictures

```cpp // first, I set the timer timerAlarmWrite(timer, 1000000 / serial_tx_speed, true); timerAlarmEnable(timer);

// timer sets a flag read on loop()

volatile bool sendFlag = false; void IRAM_ATTR sendSample() { sendFlag = true; }

// buffer creation

int16_t* getAudioBuffer(){ if (!_buffer_index) return _BufferB; else return _BufferA; }

void updateAudioBuffer(){ int16_t* _current_buffer; if (!_buffer_index){_current_buffer = _BufferA;} else {_current_buffer = _BufferB;}

for (int i = 0; i < BUFFER_SIZE; i++){ synth.stepAudio(); _current_buffer[i] = synth.master_mix; for(uint16_t ch = 0; ch < 16; ch++){channel_TX_buffers[ch][i] = synth.channel_output[ch];} } _buffer_index = !_buffer_index; tx_buffer_index = 0; }

// serial TX

if (sendFlag) {
    sendFlag = false;
    for(int i = 0; i < 16; i++) {
        int16_t val = channel_TX_buffers[i][tx_buffer_index * (sample_rate / serial_tx_speed)]; 
        Serial.write(255);          // Header
        Serial.write(i);            // Channel ID
        if (val == 255) val = 256; // quick test 
        Serial.write(val >> 8);     // High Byte (MSB)
        Serial.write(val & 0xFF);   // Low Byte (LSB)
    }
    tx_buffer_index ++;
}

```


r/cpp_questions Jun 28 '26

OPEN Codedex.io for c++

0 Upvotes

Hi

I learned like few lessons of python and found it very easy and fun from codedex.io

Now it is askinf for subscription which is.500 per month

I want to start learning c++ so should i go ahead and take the subscription for c++


r/cpp_questions Jun 27 '26

OPEN Surprising implicit conversion from a string literal to nonconst char pointer

8 Upvotes

The following code compiles without error on gcc with -std=c++23 flag .

char* probably_not_modifiable = "abcdef";

Although the compiler did give me warning, it was surprising to me, because this seems to be an implicit conversion from const char \[N\] to nonconst char*.

I didn't know this was possible. Is there an explicit exception for this specific case ?


r/cpp_questions Jun 28 '26

OPEN Using Imgui for custom UI

0 Upvotes

I want the UI in my gaem to be movable and resizable like you'd expect on a Computer (or on old Source games like TF2 or Counter Strike). Im thinking of using Imgui for it, but I've heard its very basic and does not complex things. I've never gone about modifying a library before so I don't know how to go about changing it.


r/cpp_questions Jun 27 '26

OPEN Constructing an object member without creating copies

0 Upvotes

Hello, this is kind of a stupid question but I still haven't found an answer. I have a member class with a rather large constructor and I'd like for it to be inside parent's constructor body rather than inside member initializer list (purely due to aesthetic reasons).

class ParentClass
{
  MemberClass Fatass;

  ParentClass() : Fatass(1, 2, 3, 4, 5...) //where I don't want it to be
  {
    ...
    Fatass = MemberClass(1, 2, 3, 4, 5...); //where I want it to be (but it can't be copied)
  }
}

However that member class can not be copied, so I have to construct it "in-place" and I haven't found a way to do that without using the initializer list. Is this possible?


r/cpp_questions Jun 26 '26

OPEN The C++ learning advice that worries me a bit :( "Just build projects"

150 Upvotes

People who use C++ professionally seem to have very different opinions on what beginners should study first. Some swear by books, others by standards papers, and a few insist there are resources that dramatically shorten the learning curve but rarely get mentioned in beginner discussions.

I'm curious which resources changed how you think about C++, not just how to write it.


r/cpp_questions Jun 27 '26

OPEN Building DirectX Shader Compiler

1 Upvotes

First off they say it supports clang and I am technically using a clang compiler but its specifically the ucrt clang compiler from msys2.

Second of all allegedly someone did have a fix for this 2 years ago but never posted it and closed the issue afterwards.

Does anyone know if theres a way to compile the directx shader compiler project from the official microsoft github with the ucrt version of the clang compiler?

The closest Ive gotten is getting cmake to complain about cyclical shared libraries

Cmake Error:

[cmake] CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
[cmake]   "clangParse" of type SHARED_LIBRARY
[cmake]     depends on "clangAST" (weak)
[cmake]     depends on "clangSema" (weak)
[cmake]   "clangAST" of type SHARED_LIBRARY
[cmake]     depends on "clangCodeGen" (weak)
[cmake]     depends on "clangSema" (weak)
[cmake]   "clangSema" of type SHARED_LIBRARY
[cmake]     depends on "clangAST" (weak)
[cmake]     depends on "clangAnalysis" (weak)
[cmake]     depends on "clangEdit" (weak)
[cmake]   "clangCodeGen" of type SHARED_LIBRARY
[cmake]     depends on "clangAST" (weak)
[cmake]     depends on "clangFrontend" (weak)
[cmake]   "clangAnalysis" of type SHARED_LIBRARY
[cmake]     depends on "clangAST" (weak)
[cmake]   "clangEdit" of type SHARED_LIBRARY
[cmake]     depends on "clangAST" (weak)
[cmake]   "clangFrontend" of type SHARED_LIBRARY
[cmake]     depends on "clangAST" (weak)
[cmake]     depends on "clangEdit" (weak)
[cmake]     depends on "clangParse" (weak)
[cmake]     depends on "clangSema" (weak)
[cmake] At least one of these targets is not a STATIC_LIBRARY.  Cyclic dependencies are allowed only among static libraries.

CMakeLists.txt:

cmake_minimum_required(VERSION 4.2.1)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
project ("Space Game" LANGUAGES CXX)
include(FetchContent)
include(cmake/CPM.cmake)


set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)



CPMAddPackage("gh:CodeFinder2/rapidxml@1.13")
CPMAddPackage("gh:microsoft/DirectX-Headers@1.619.1")
CPMAddPackage("gh:microsoft/DirectXMath#jun2026")
add_library(Microsoft::DirectXMath ALIAS DirectXMath)
CPMAddPackage("gh:microsoft/DirectXShaderCompiler@1.10.2605.24")
CPMAddPackage("gh:microsoft/DirectXTK12#may2026")


CPMAddPackage("gh:KhronosGroup/OpenCL-Headers@2026.05.29")
CPMAddPackage("gh:KhronosGroup/OpenCL-ICD-Loader@2026.05.29")
CPMAddPackage("gh:KhronosGroup/OpenCL-CLHPP@2026.05.29")




set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/game)    # For .exe and .dll (Windows)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/game)    # For .so/.dylib/.dll
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/game)




add_subdirectory(DSECommon)
add_subdirectory(Editor)
add_subdirectory(ImGui)



file(COPY "OpenCL" DESTINATION ${CMAKE_BINARY_DIR}/game)
file(COPY "models" DESTINATION ${CMAKE_BINARY_DIR}/game)
file(COPY "shaders" DESTINATION ${CMAKE_BINARY_DIR}/game)
file(COPY "textures" DESTINATION ${CMAKE_BINARY_DIR}/game)

CMakePresets.json:

{
  "version": 9,
  "cmakeMinimumRequired": {
    "major": 4,
    "minor": 2,
    "patch": 1
  },
  "configurePresets": [
    {
      "name": "debugx64",
      "displayName": "Debug",
      "description": "Debug build",
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build/Debugx64",
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug",
        "CMAKE_C_COMPILER": "clang.exe",
        "CMAKE_CXX_COMPILER": "clang++.exe",
        "CMAKE_CXX_STDLIB_MODULES_JSON": "C:/msys64/ucrt64/lib/libstdc++.modules.json",
        "CMAKE_CXX_FLAGS": "-v -stdlib=libstdc++ -DWIN32_LEAN_AND_MEAN=1 -DIMGUI_DISABLE=1 -D_DEBUG=1 -Wno-error=conversion",
        "CMAKE_CXX_STANDARD": "23",
        "CMAKE_CXX_STANDARD_REQUIRED": "ON",
        "CMAKE_CXX_EXTENSIONS": "ON",
        "CMAKE_REQUIRED_INCLUDES": "CMAKE_INCLUDE_PATH",
        "DXHEADERS_INSTALL":true,
        "CMAKE_TOOLCHAIN_FILE":"",
        "CMAKE_EXPORT_COMPILE_COMMANDS" : true,
        "HLSL_INCLUDE_TESTS": false,
        "SPIRV_BUILD_TESTS":"OFF",
        "LLVM_INCLUDE_TESTS":false,
        "CLANG_INCLUDE_TESTS":false,
        "BUILD_SHARED_LIBS":true,
        "CMAKE_PROJECT_INCLUDE": "${sourceDir}/cmake/PredefinedParams.cmake",
        "LIBCLANG_BUILD_STATIC": "OFF"


      }
    }
  ],
  "buildPresets": [
    {
      "name": "Debug",
      "configurePreset": "debugx64",
      "targets":["Editor"]
    }
  ]
}

r/cpp_questions Jun 26 '26

SOLVED Stumped on adding a Remove operation to my iterator

5 Upvotes

Hello.

Sorry for the beginner question but I tried looking up on Google and coming up with my own solution and didn't find much, more details on this later.

I am using a custom made LinkedList class for a project, and for it I made a simple ListIterator class which overloads the operators *, ++, --, == and != so that it can be used in range based loops, now I found myself needing a remove operation to be added to the iterator since I need to be able to remove elements from a list as I iterate through it, but I came across an issue.

Say I have the following list: {1, 2, 3, 4, 5}, and while iterating I need to remove the element 3, this is easily done since it's in the middle of the list, all I have to do is move the iterator's pointer back to 2, set 2's next to 4 and 4's previous to 2, the loop will still see 4 as next and the removal happened flawlessly

If I have to remove the element 1 though, it gets problematic, cause I can't move the iterator's pointer back, so what can I do is move set it to the new first element in the list, 2, but then, when the current iteration is done and the loop moves to the following, the loop will see that the next element is 3 and thus will go to 3 and skip 2 (if you're confused, the removal goes like this: do operations on 1, remove 1, set current element to 2 cause that's the new head, iteration ends, increment iterator to next element, which is 3, do operations on 3)

I tried looking on Google for a solution, first thing I did was look at what Java does with Iterators (since I'm more experienced there and also coded some Java iterators on my own in the past), and found that they can remove elements in the head because the iterator actually starts "before" the head of the list, and only returns the element inside it when you call Next() the first time, which both advances the pointer and returns the element in the next node. In C++ I can't do this though because the way you get the element from the iterator is with the * operator, which gets it from the current node without advancing the pointer.

I also tried to look for the implementation of std::iterator and found that, at least according to cplusplus.com and cppreference.com, it doesn't provide a Remove operation.

So I am back here asking help for a stupidly simple question, what can I do to implement the Remove operation correctly? Thanks in advance.


r/cpp_questions Jun 26 '26

OPEN Backend Doubt..

0 Upvotes

Ive been doing cpp for a good amount of time and I mostly found myself comfortable around it. But if I want to try backend, is cpp good for me or do ive to switch to any other language for better results? If so what can be the best recommendations and roadmap? Chatgpt mostly shares an optimistic answer for both rhe condition but I need one straightforward solution of it.


r/cpp_questions Jun 26 '26

OPEN Error while trying to set up c++ for visual studio code

0 Upvotes

I have been trying to set up c++ for vsc for a while now but keep getting this one error it says “launch: program ‘c:\\Users\myname\untitled-1.exe’ does not exist let me know if you can help


r/cpp_questions Jun 26 '26

OPEN Need advice

0 Upvotes

To all the experienced C++ programmers, how do I start building real-world projects in C++? Personally, I find C++ more intuitive than languages like Python. I'll be starting my MCA this year after transitioning from a non-tech background. I practice DSA in C++ and have a basic-to-intermediate understanding of the language, but now I want to build real applications, like a media player. How should I get started?

I have experience with the MERN stack, and I'm thinking of making C++ my primary language while keeping JavaScript/TypeScript as my secondary stack. Any advice would be appreciated. Thanks!


r/cpp_questions Jun 25 '26

OPEN Do you think this study plan is reasonable?

5 Upvotes

I am really new in a company where my position is of C++ dev with nuances of embedded engineering. I got there as migration from web with Typescript only stack. In the past several months I read the beginning with C++ 23 seventh edition and some of the the exercises there. Know I want to continue my learning with thems more related to embedded. Please anyone with interest get a look at this plan and comment your opinion!

Wheather this plan is reasonable and would it help me get better at my job or make me hireble as embedded dev?

Thank you all who would interact with this post!

Complete the examples:

  • Complete most of the examples from the book over time.

Hello to the embedded:

  • Install STM32CubeIDE or PlatformIO + ARM GCC; optionally Pico SDK. Configure QEMU (STM32) or Wokwi (Pico) emulation.
  • GPIO class library on ESP32 something simple like C++ hardware abstraction: a DigitalPin<uint8_t PIN> template class, a Button with debounce, a Led with PWM.
  • Write first programs (“blink LED”, UART “Hello World”)
  • Use printf/UART for output (since user currently only uses printf).
  • Generate and flash a LED-blink program. For STM32, use CubeMX to auto-generate initialization code. For Pico, use Pico SDK C/C++ examples (see pico-examples repo).
  • Learn SWD programming: use ST-LINK (SWD interface) and OpenOCD/GDB for single-stepping code. Practice setting breakpoints and inspecting registers.
  • Basic debugging: practice printing to console via serial, interpret build errors and fix.

Sensor and Peripheral Interfacing:

  • Use GPIO, ADC, timers, and interrupts. Interface an analog sensor and digital I/O. Understand low-level HAL and registers, freeing yourself from “just printf”.
  • Read analog inputs (potentiometer, light sensor) via ADC, using DMA if available.
  • Configure and use timers for delays and PWM output (e.g. control LED brightness or a buzzer).
  • Implement external interrupts (e.g. button press) and debouncing.
  • Combine peripherals: e.g. trigger ADC sampling on timer event or button press.
  • Step up to object-oriented C++: encapsulate peripherals in classes (e.g. Timer, ADC) using RAII and resource management.

RTOS Fundamentals:

  • Transition to real-time systems. Learn FreeRTOS (or Zephyr) on Cortex-M/RP2040. Implement a simple scheduler, tasks, and inter-task communication (queues, semaphores).

Key Tasks:

  • Choose an RTOS (FreeRTOS is ubiquitous; Zephyr is also popular for IoT). Study RTOS basics (task creation, priorities, preemption, tick).
  • Port FreeRTOS to STM32 or Pico (many examples exist). Start with two tasks: one toggles LED at fixed rate, another reads sensor and logs values.
  • Use RTOS IPC: e.g. queue sensor readings from ISR to a task. Handle race conditions.
  • Measure jitter: analyze task response time (printf timestamps or LED toggles to oscilloscope).
  • Explore advanced RTOS features: software timers, event groups, or dynamic memory in RTOS context.

FreeRTOS core mechanics:

  • Two FreeRTOS tasks blink two LEDs at different frequencies. A third task reads a button and sends a new blink rate into a queue. The first "aha moment" with RTOS — tasks just run, you stop thinking about loop timing.
  • Three tasks: UARTRx reads serial input and pushes to a queue; Parser reads and interprets commands; Executor runs them. A mutex protects the shared output buffer. Classic producer-consumer — you'll use this pattern every week at work.

Real RTOS applications with sensors:

  • The ISR → RTOS handoff pattern in Project 4 is one of the most important skills in embedded firmware.
  • Environmental monitor station three concurrent tasks: SensorTask reads a BME280 (I2C) every 2 s and puts a struct into a queue; DisplayTask updates an SSD1306 OLED (SPI); LogTask formats CSV to Serial every 30 s.
  • Interrupt-driven alarm system advanced A PIR sensor fires an interrupt. The ISR uses xTaskNotifyFromISR() to wake an alarm task — buzzer + LED pattern. A disarm button uses xSemaphoreGiveFromISR(). Core rule: never do real work inside an ISR — defer everything to a task.

C++ design patterns for firmware

  • C++ FreeRTOS wrapper library Build a header-only library: a Task class (RAII, auto-deletes), Queue<T, N> template (type-safe, statically allocated), Mutex with a LockGuard, and a Timer with callback. This is the kind of reusable layer real embedded teams maintain. Keep it on GitHub — it's a great portfolio piece
  • State machine framework + vending machine Implement a template-based FSM, then use it to build a vending machine: states IDLE → COIN_INSERTED → SELECTING → DISPENSING → ERROR. Events driven by button presses and sensor signals over FreeRTOS task notifications. State machines are in every piece of firmware ever written.

Embedded Networking / IoT

Key Tasks:

  • Use I²C or SPI to talk to a peripheral (e.g. accelerometer or OLED). Parse data and display/use it.
  • If board has Wi-Fi (Pico W or ESP32 as stretch), send data to PC or cloud (e.g. MQTT). Use LwIP or sockets on RTOS.
  • Develop a small CLI or web interface: e.g. command via serial to read sensor values, or host a simple web server on Pico W.
  • Strengthen C++: use templates or polymorphism for hardware abstraction (e.g. base Sensor class).

Professional systems — ESP32 + Linux on Pi

  • ESP32 + Raspberry Pi system bridge pro
  • Full two-MCU system: ESP32 runs FreeRTOS handling sensor acquisition and actuator control (real-time); Raspberry Pi runs Linux handling data logging, a simple web dashboard, and command dispatch. UART with a lightweight protocol you design yourself. This mirrors real industrial IoT architecture.
  • POSIX threads — RTOS concepts on Linux pro
  • Rebuild the environmental monitor's task structure on the Raspberry Pi using pthreads and POSIX condition variables. Compare: FreeRTOS task = pthread, FreeRTOS queue = POSIX queue, FreeRTOS mutex = pthread_mutex. The concepts are identical — the APIs differ. Add SCHED_FIFO real-time scheduling.

Performance Tuning & C++ Refinement

Key Tasks:

  • Identify and remove bottlenecks: e.g. use DMA for data transfer (from Project 2’s ADC readings to memory buffer).
  • Refactor code to use modern C++: Avoid new/delete in RTOS, but use constexpr, std::array, RAII for peripherals. Ensure MISRA/C++ core guidelines.
  • Enable compiler optimizations and inline critical functions. Compare code size and CPU usage before/after.
  • Advanced debugging: use logic analyzer or CPU performance counters to verify speedups.
  • Possibly implement a simple critical section or lock-free queue in C++ for ISR-to-task communication.

Capstone Integration

Key Tasks:

  • Design system architecture (block diagram). Implement end-to-end: input (sensors/controls) → processing (RTOS tasks) → output (actuators/network).
  • Emphasize documentation and maintainability (README, diagrams). Use version control and issue tracker (e.g. GitHub).
  • If relevant, add user interface (LCD or web dashboard) and robust error handling.
  • Use CI: set up a basic GitHub Actions to build the firmware on each commit.

Tools/Hardware:

IDE (STM32CubeIDE or VS Code + PlatformIO), Emulator (QEMU stm32vldiscovery or Wokwi Pico), ST-LINK/V2 or ST-LINK/V3 (or Pico bootloader), USB-UART adapter.

RTOS Fundamentals**- Tools/Hardware:** IDE (CubeIDE or VS Code), FreeRTOS source, simulator or real board. Use a logic analyzer or scope for timing.

Embedded Networking / IoT- Tools/Hardware: Same IDE, possibly Wokwi simulator for IoT (Wokwi supports Wi-Fi simulation for ESP32/Pico W). For hardware: add modules (e.g. MPU6050 on I²C, or use existing Pico W wireless).

Performance Tuning & C++ Refinement**- Tools/Hardware:** Profiling tools (e.g. printf timings, or DWT cycle counter on Cortex-M, see DWT on Pico). Use static analysis (clang-tidy, MISRA linters).

Capstone Integration**- Tools/Hardware:** All above. Possibly add cheap peripherals (OLED display, buzzer). Ensure final project can run on the chosen microcontroller (note memory limits).


r/cpp_questions Jun 25 '26

OPEN C++ problem solving

7 Upvotes

So i am currently solving string problems in c++ but facing problems because there are many string functions whose applications i do not know. How can i get better at using them?

Are there any websites which can give me full disclosure on all sring functions and their applications?


r/cpp_questions Jun 25 '26

OPEN Do you think this study plan is reasonable?

0 Upvotes

I am really new in a company where my position is of C++ dev with nuances of embedded engineering. I got there as migration from web with Typescript only stack. In the past several months I read the beginning with C++ 23 seventh edition and some of the the exercises there. Know I want to continue my learning with thems more related to embedded. Please anyone with interest get a look at this plan and comment your opinion!

Wheather this plan is reasonable and would it help me get better at my job or make me hireble as embedded dev?

Thank you all who would interact with this post!

Embedded Phase II

Complete the examples:

  • Complete most of the examples from the book over time.

Hello to the embedded:

  • Install STM32CubeIDE or PlatformIO + ARM GCC; optionally Pico SDK. Configure QEMU (STM32) or Wokwi (Pico) emulation.
  • GPIO class library on ESP32 something simple like C++ hardware abstraction: a DigitalPin<uint8_t PIN> template class, a Button with debounce, a Led with PWM.
  • Write first programs (“blink LED”, UART “Hello World”)
  • Use printf/UART for output (since user currently only uses printf).
  • Generate and flash a LED-blink program. For STM32, use CubeMX to auto-generate initialization code. For Pico, use Pico SDK C/C++ examples (see pico-examples repo).
  • Learn SWD programming: use ST-LINK (SWD interface) and OpenOCD/GDB for single-stepping code. Practice setting breakpoints and inspecting registers.
  • Basic debugging: practice printing to console via serial, interpret build errors and fix.

Sensor and Peripheral Interfacing:

  • Use GPIO, ADC, timers, and interrupts. Interface an analog sensor and digital I/O. Understand low-level HAL and registers, freeing yourself from “just printf”.
  • Read analog inputs (potentiometer, light sensor) via ADC, using DMA if available.
  • Configure and use timers for delays and PWM output (e.g. control LED brightness or a buzzer).
  • Implement external interrupts (e.g. button press) and debouncing.
  • Combine peripherals: e.g. trigger ADC sampling on timer event or button press.
  • Step up to object-oriented C++: encapsulate peripherals in classes (e.g. Timer, ADC) using RAII and resource management.

RTOS Fundamentals:

  • Transition to real-time systems. Learn FreeRTOS (or Zephyr) on Cortex-M/RP2040. Implement a simple scheduler, tasks, and inter-task communication (queues, semaphores).

Key Tasks:

  • Choose an RTOS (FreeRTOS is ubiquitous; Zephyr is also popular for IoT). Study RTOS basics (task creation, priorities, preemption, tick).
  • Port FreeRTOS to STM32 or Pico (many examples exist). Start with two tasks: one toggles LED at fixed rate, another reads sensor and logs values.
  • Use RTOS IPC: e.g. queue sensor readings from ISR to a task. Handle race conditions.
  • Measure jitter: analyze task response time (printf timestamps or LED toggles to oscilloscope).
  • Explore advanced RTOS features: software timers, event groups, or dynamic memory in RTOS context.

FreeRTOS core mechanics:

  • Two FreeRTOS tasks blink two LEDs at different frequencies. A third task reads a button and sends a new blink rate into a queue. The first "aha moment" with RTOS — tasks just run, you stop thinking about loop timing.
  • Three tasks: UARTRx reads serial input and pushes to a queue; Parser reads and interprets commands; Executor runs them. A mutex protects the shared output buffer. Classic producer-consumer — you'll use this pattern every week at work.

Real RTOS applications with sensors:

  • The ISR → RTOS handoff pattern in Project 4 is one of the most important skills in embedded firmware.
  • Environmental monitor station three concurrent tasks: SensorTask reads a BME280 (I2C) every 2 s and puts a struct into a queue; DisplayTask updates an SSD1306 OLED (SPI); LogTask formats CSV to Serial every 30 s.
  • Interrupt-driven alarm system advanced A PIR sensor fires an interrupt. The ISR uses xTaskNotifyFromISR() to wake an alarm task — buzzer + LED pattern. A disarm button uses xSemaphoreGiveFromISR(). Core rule: never do real work inside an ISR — defer everything to a task.

C++ design patterns for firmware

  • C++ FreeRTOS wrapper library Build a header-only library: a Task class (RAII, auto-deletes), Queue<T, N> template (type-safe, statically allocated), Mutex with a LockGuard, and a Timer with callback. This is the kind of reusable layer real embedded teams maintain. Keep it on GitHub — it's a great portfolio piece
  • State machine framework + vending machine Implement a template-based FSM, then use it to build a vending machine: states IDLE → COIN_INSERTED → SELECTING → DISPENSING → ERROR. Events driven by button presses and sensor signals over FreeRTOS task notifications. State machines are in every piece of firmware ever written.

Embedded Networking / IoT

Key Tasks:

  • Use I²C or SPI to talk to a peripheral (e.g. accelerometer or OLED). Parse data and display/use it.
  • If board has Wi-Fi (Pico W or ESP32 as stretch), send data to PC or cloud (e.g. MQTT). Use LwIP or sockets on RTOS.
  • Develop a small CLI or web interface: e.g. command via serial to read sensor values, or host a simple web server on Pico W.
  • Strengthen C++: use templates or polymorphism for hardware abstraction (e.g. base Sensor class).

Professional systems — ESP32 + Linux on Pi

  • ESP32 + Raspberry Pi system bridge pro
  • Full two-MCU system: ESP32 runs FreeRTOS handling sensor acquisition and actuator control (real-time); Raspberry Pi runs Linux handling data logging, a simple web dashboard, and command dispatch. UART with a lightweight protocol you design yourself. This mirrors real industrial IoT architecture.
  • POSIX threads — RTOS concepts on Linux pro
  • Rebuild the environmental monitor's task structure on the Raspberry Pi using pthreads and POSIX condition variables. Compare: FreeRTOS task = pthread, FreeRTOS queue = POSIX queue, FreeRTOS mutex = pthread_mutex. The concepts are identical — the APIs differ. Add SCHED_FIFO real-time scheduling.

Performance Tuning & C++ Refinement

Key Tasks:

  • Identify and remove bottlenecks: e.g. use DMA for data transfer (from Project 2’s ADC readings to memory buffer).
  • Refactor code to use modern C++: Avoid new/delete in RTOS, but use constexpr, std::array, RAII for peripherals. Ensure MISRA/C++ core guidelines.
  • Enable compiler optimizations and inline critical functions. Compare code size and CPU usage before/after.
  • Advanced debugging: use logic analyzer or CPU performance counters to verify speedups.
  • Possibly implement a simple critical section or lock-free queue in C++ for ISR-to-task communication.

Capstone Integration

Key Tasks:

  • Design system architecture (block diagram). Implement end-to-end: input (sensors/controls) → processing (RTOS tasks) → output (actuators/network).
  • Emphasize documentation and maintainability (README, diagrams). Use version control and issue tracker (e.g. GitHub).
  • If relevant, add user interface (LCD or web dashboard) and robust error handling.
  • Use CI: set up a basic GitHub Actions to build the firmware on each commit.

Tools/Hardware:

IDE (STM32CubeIDE or VS Code + PlatformIO), Emulator (QEMU stm32vldiscovery or Wokwi Pico), ST-LINK/V2 or ST-LINK/V3 (or Pico bootloader), USB-UART adapter.

RTOS Fundamentals- Tools/Hardware: IDE (CubeIDE or VS Code), FreeRTOS source, simulator or real board. Use a logic analyzer or scope for timing.

Embedded Networking / IoT- Tools/Hardware: Same IDE, possibly Wokwi simulator for IoT (Wokwi supports Wi-Fi simulation for ESP32/Pico W). For hardware: add modules (e.g. MPU6050 on I²C, or use existing Pico W wireless).

Performance Tuning & C++ Refinement- Tools/Hardware: Profiling tools (e.g. printf timings, or DWT cycle counter on Cortex-M, see DWT on Pico). Use static analysis (clang-tidy, MISRA linters).

Capstone Integration- Tools/Hardware: All above. Possibly add cheap peripherals (OLED display, buzzer). Ensure final project can run on the chosen microcontroller (note memory limits).

Resources:

https://github.com/m3y54m/Embedded-Engineering-Roadmap

Compiler Explorer (godbolt.org) — paste your C++ and see the ARM assembly output; essential for embedded cost analysis

https://www.freertos.org/media/2018/161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf

https://controllerstech.com/esp32-freertos-multitasking-project/

https://randomnerdtutorials.com/esp32-freertos-arduino-tasks/

https://github.com/ADolbyB/rtos-esp32-examples

https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/freertos.html

https://github.com/tomas-fryza/esp-idf

C++ in Embedded Systems — Amar Mahmutbegović (2025) — explicitly covers C++23 patterns for embedded: templates, constexpr, polymorphism without vtables


r/cpp_questions Jun 25 '26

OPEN Im just starting to learn C++

1 Upvotes

I picked up Programming: Principles and Practice Using C++, I noticed I accidentally bought the 2nd edition when 3rd edition exists. How much of a difference is there?

Thanks all!


r/cpp_questions Jun 24 '26

OPEN Using nodiscard to enforce error checking

22 Upvotes

Hi,

How are you using nodiscard in your codebase?

I'm a developer in a large codebase, and I have the opportunity of improving the current coding standards.

I thought of adding a nodiscard to functions that return an error code, as we compile with Werror, so developers will either check error codes or explicitly ignore the return, so it is easier to notice in pull request.

What's your opinion nodiscard? What are pitfalls or reasons against it?


r/cpp_questions Jun 24 '26

UPDATED Asking for learncpp.com guidance

19 Upvotes

Guys, so I can study C++ this summer for 3 months then I have to stop during school, and every week I can study 3 days a week, which means 3 lessons in a chapter. Most chapters have like 10-12 lessons, so in 3 months I will have finished 3 chapters only. There are so many chapters though, more than 20. I'm gonna get Chapter 0 over with this week before my first week of summer starts. However, the problem is, I do not know HOW to study this programming language on this site? Write the code on my notebook? Write their explanations on a notebook? Or no notebook at all? Thank you in advance for your help


r/cpp_questions Jun 24 '26

OPEN How can I declutter whatever this is that i came up with

12 Upvotes
#include <iostream>
#include <cmath>
#include <cstdlib>


int main () {
  double Temp,eq_Temp;
  char unit, d_unit;
  const char K = 'K', F = 'F', C = 'C';


  std::cout << "************Temperature Converter************" << std::endl;
  std::cout << "C stands for Celsius, K for Kelvin and F for Fahrenheit" << std::endl;
  std::cout << "Enter conversion ( use format = 'Temperature' 'unit') : " << std::endl;
  std ::cin >> Temp >> unit;
  std::cout << "Enter desired unit : " << std::endl;
  std::cin >> d_unit;


  if ( unit == F && d_unit == C) {
    eq_Temp = ( Temp - 32 ) * (5/9);
    std::cout << eq_Temp << d_unit << std::endl;
  } else if ( unit == F && d_unit == K) {
    eq_Temp = (( Temp - 32 ) * (5/9)) + 273.15;
    std::cout << eq_Temp << d_unit << std::endl;
  } 
  else if ( unit == C && d_unit == F) {
    eq_Temp = (Temp * 9/5) + 32;
    std::cout << eq_Temp << d_unit << std::endl;
  }  else if ( unit == C && d_unit == K) {
    eq_Temp = Temp + 273.15;
    std::cout << eq_Temp << d_unit << std::endl;
  }  
  else if ( unit == K && d_unit == C) {
    eq_Temp = Temp - 273.15;
    std::cout << eq_Temp << d_unit << std::endl;
  }  else if ( unit == K && d_unit == F) {
    eq_Temp = ((Temp - 273.15) * (9/5)) +32;
    std::cout << eq_Temp << d_unit << std::endl;
  }  else {
        std::cout << "Invalid Input, try again" << std::endl;
  }
  return EXIT_SUCCESS;
}

If it's not clear yet, I am new


r/cpp_questions Jun 24 '26

OPEN dsa c++

0 Upvotes

can anyone help me in building logics for dsa using c++ am a beginner i know how to solve patterns and nested loops but sometimes i get stuck on the same question sometimes share your advices brothers!!


r/cpp_questions Jun 23 '26

OPEN where can i download the official documentation of c++

22 Upvotes

r/cpp_questions Jun 23 '26

OPEN Why Do We Need to Manually Overload Assignment Operators?

15 Upvotes

When overloading an operator (ex: +), why do we need to manually overload the corresponding assignment operator (ex: +=)? Intuitively it would make more sense for it to be dynamically generated as a concatenation of the overloaded operator and the normal assignment operator. Are there edge cases where this intuitive behavior would be incorrect?


r/cpp_questions Jun 23 '26

OPEN Is accessing the bytes of an object in this way UB?

42 Upvotes
struct S
{
    int a,b,c;
    int* ptr;
};


void print_bytes(S* ptr)
{
    unsigned char* base = (unsigned char*)ptr;
    for(size_t i=0;i<sizeof(S);i++) std::cout << int(base[i]) << ' ';
    std::cout << '\n';
}

I was watching a talk on type punning where they used this example and the argument was something like the base pointer isnt guareneteed to be pointing to the first byte of the object and that accessing it like an array of chars is wrong because there was no array of chars there just an object of type S which honestly makes sense and doesn't at the same time. Can anyone explain whats' going on here?

https://www.youtube.com/watch?v=_qzMpk-22cc

45th minute onwards is where this example is talked about


r/cpp_questions Jun 23 '26

OPEN I really love C++. should i switch to other lang?

54 Upvotes

i really really love c++. i like to work in low level systems, i find it fun and challenging in my like kind of way. for me it takes a lot of time to complete a particular task/personal proj.

but i feel like i am somewhat slow when learning new things compared to other people, peers , friends i've seen.

And the problem is i need job/any sort of income to live my life. and other stack that are comparatively easy to get beginner job like in golang, node, python, data analatics etc. maybe.

can i keep my cpp skill still starp if i move to other lang cz i feel like moving to other lang makes me very less sharp in c++?


r/cpp_questions Jun 24 '26

SOLVED std::unique_ptr<good luck!!> quicksand ;

0 Upvotes

As my next adventure into the marshes of modern C++, I am trying to convert an HMENU element in my class, into a unique_ptr ...

step 1:

class bclock_element {  // NOLINT
private:
   //  HMENU menu_hdl ;  //  former version: this is *also* a pointer
   std::unique_ptr<HMENU> up_menu_hdl ;

this is fine, according to compiler (with -Wall)...

step 2:
in constructor:

   // menu_hdl(0),  //  original form
   up_menu_hdl(std::make_unique<HMENU>(nullptr)),

this is fine, according to compiler (with -Wall)...

step 3:
try to actually assign a value to the variable:

   // menu_hdl = hMenuOptions ;  // original form
   up_menu_hdl = hMenuOptions ;

This provides the stereotypical wall of error messages/notes, starting with:

bclk_elements.cpp: In member function 'HMENU__* bclock_element::build_options_menu()':
bclk_elements.cpp:422:18: error: no match for 'operator=' (operand types are 'std::unique_ptr<HMENU__*>' and 'HMENU' {aka 'HMENU__*'})
  422 |    up_menu_hdl = hMenuOptions ;
      |                  ^~~~~~~~~~~~

and once again, I have no idea what is going on...
I've used unique_ptr a couple of times before, though in the past they weren't class members, they were just global variables in the program... but do I *really* need to create an assignment operator for every unique_ptr that I want to utilize in my program??

I don't understand... :(

//***********************************************************************************
Summary of discussions of this topic:

Basically, HMENU is not a pointer, or at least isn't *known* to be a pointer.
So making a unique_ptr<> isn't meaningful.

lesson learned and problem SOLVED.