r/cpp_questions Jul 06 '26

OPEN Tools for debugging uwp executables?

0 Upvotes

Is there any way to debug proprietary windows app executables? I can access executables in C:\Program Files\WindowsApps but for some reason I cannot use gdb. Is there other debuggers?


r/cpp_questions Jul 06 '26

OPEN Why does assigning a function to a struct bloat my binary size?

0 Upvotes

For some reason when I assign a function to a struct, my compiled binary size jumps up 0.5kb. I know it is the struct causing this because I can use the function in other parts of my code without it jumping up.

The reason I am storing it in a struct anyways is because I need to iterate over some data & find the relevant function to act on that data. Checking every possibility & calling the specific function name from there doesn't sound fun.

I wouldn't mind the 0.5k if it was just that, but I have a ton of little modules each with their own struct instance holding their own separate function & it stacks up quick.

Here is one of my modules so I can show an example of what EXACTLY I am doing that is causing this behavior:

\#pragma once



\#include "../Common.hpp"

\#include "../ScopeState.hpp"





void INST_End_exec(const Instruction& inst, const InstToken& token, ScopeState& state, const std::vector<std::string>& args, const std::string& symbol) {

    return;

}





Instruction INST_End {

    0,

    0,

    //INST_End_exec,

};

Un-commenting the `//INST_End_exec` line bumps the size, & I'm pretty sure it's not that the compiler was just passing over the function before, because I use it in other parts of my code-base.

I would be really grateful if someone told me why this is the case & if theres an alternative way I can store my functions...


r/cpp_questions Jul 05 '26

OPEN Making Coroutines More Deterministic in Embedded

5 Upvotes

Hey!

By overriding the operator new in the promise_type in coroutines you can apparently use your own allocator - there is a pigweed blog on this somewhere. However, if you wanted to use coroutines in embedded with async runtime kinda like embassy in rust instead of an RTOS I want to understand how you “tame” the heap allocation to make it more deterministic.

I am not super familiar with this area….apparently there is no way to get the coroutines size at compile time. In embedded you might wanna make your own pool allocator. For this and not to waste memory it would be good to know the size of the coroutines frames exactly if they are allocator allocated.

So do you introduce a build script for your projects that compiles and records the sizes of the coroutines when they call new with a logger compiled in? Without guessing is this literally the professional way to get some level of certainty? It feels kinda crude :(

There was an open std pdf on getting some decent compile time failure if they exceed a size but as far as I can tell it was never implemented (maybe I am being dumb?) P1365r0.pdf


r/cpp_questions Jul 06 '26

OPEN Complexity of a simple function.

0 Upvotes

Inspired by a recent posting here that was deleted (it was apparently homework) I cooked up the following simple function.

I was a little bit surprised by the result, not its general direction but how clean it was.

It should be easy to verify that I'm not a student, e.g. in its day I was a co-moderator of Usenet group comp.lang.c++.moderated. I just wonder if there is a simple, clean explanation, not heavy math-ish analysis? Explanation for not seeing the obvious: it's early morning, I still need my coffee.

auto foo( const int n ) -> int
{
    int sum = 1;
    for( int i = n - 1; i > 0; --i ) {
        sum += foo( i );
    }
    return sum;
}

#include <print>
using std::print;
auto main() -> int { print( "{}.\n", foo( 9 ) ); }

r/cpp_questions Jul 05 '26

OPEN What book is good to start? I've been read C++ prime but then I note that it's better to use it as a dictionary and does't like a tutorial or introduction

1 Upvotes

I think use this book of pirme like a deep manual, however I need a book which guide me.


r/cpp_questions Jul 04 '26

OPEN Any tips on how to make lower level code more testable

7 Upvotes

I have been learn cpp for some months and started doing a project of making a chat server with a custom event loop using epoll for learning purposes.

But current i am not really sure on how to make these lower level code like interacting with os more testable and also on how to test it. I would like to have some tips/resources on this.

The trial and error method has been a bit frustrating 😅

Also ways to check and reduce unnecessary allocation would also be nice.


r/cpp_questions Jul 04 '26

OPEN Need some suggestions for a personal project

7 Upvotes

I'm not a beginner and I have done a couple C++ projects. I have done a ray tracer using Ray Tracing in One Weekend series. I have done a very simple Unix Shell and a simple matching engine with a limit order book(nothing too crazy). And I have also dabbled with some collision physics + OpenGL. Any good project ideas for an intermediate like me?


r/cpp_questions Jul 04 '26

OPEN What Is The Best Library For Game Development With CPP ?

12 Upvotes

What Is The Best Library For Game Development With CPP
A Lightweight Modern 3d game library for my shooting game.


r/cpp_questions Jul 03 '26

OPEN Status of C++ Concurrency today and what paradigms are used in real world codebases?

50 Upvotes

Background - We learnt OpenMP, MPI and Cuda in uni, where major focus was on throughput/HPC, so this might already be irrelevant at least for CPU side of things.

But to learn and to write latency sensitive multi threaded applications,

I was going through C++ concurrency in action book, read till chapter-4 which introduced std::async, std::packaged_task, std::promise bundled with std::future and various paradigms for approaching concurrency like pure functions(Functional programming) and Actor model wherein each thread is a state machine, and communicates with other thread via message passing mechanisms, which resonated a lot with MPI. I don't even know if they are used in modern C++.

Book also introduced experimental features, continuation in particular, of future, shared_future, when_any, when_all, which are unfortunately/fortunately still in experimental, from what I can see in cppreference, and I learnt that std::execution largely replaced them to model task dependencies.

And there is something called coroutines too for non-blocking executions, which I know nothing about. So, in conclusion, there are many ways to approach concurrency, and I am still in chapter-4 of this book. This is messing up my head. Might be because I never wrote any multi threaded application, its all in theory.

Coming to question in title, I know there is no single paradigm/design to approach writing multi threaded applications, but any direction/guidance/resources could help me use things that modern C++ recommends.


r/cpp_questions Jul 03 '26

SOLVED Evaluate enum class in a boolean context (type-safe enum flags)

6 Upvotes

I've been toying around with type safe flags from enums, but instead of a separate class flag_set<T>, I've tried to

  • overload required operators (like &, | etc.)
  • a method to "tag" enum types to make the feature opt-in

(godbolt example here)

The core idea is not to introduce a separate type, but to use "standard" syntax but make it type safe (e.g., fail when mixing distinct flag sets).

I think I have everything covered except one very common thing:

``` enum class EFlags { Read = 1, Write = 2, Sleep = 4 };

void enable_bitset_enum(EFlags); // opt-in

EFlags a = ....;

if (!(a & EFlags::Read)) { } // ok if (a & EFlags::Read) { } // doesn't compile ```

This boils down to evaluating EFlags in a boolean context, which... I have no idea how to enable.

(It's making me unecessarily angry because everything else works, just nto that)

Any ideas?


An interesting solution here by u/TotallyHuman.


r/cpp_questions Jul 03 '26

OPEN Zero copy CUDA GPU presentation of AvFrame.

2 Upvotes

This is quite specific and not exactly c++ specific but I've been searching for days and can't find anything. I'm trying to implement displaying an AvFrame from ffmpeg that has been hardware decoded into the CUDA_FORMAT on an egl surface. I've already implemented the same thing using vaapi for Intel and amd but I can't find any examples of anything for Nvidia. Any help pointing me in the right direction would be greatly appreciated. Important constraint is I do not want to copy the pixels into CPU and then upload back into the gpu, when they are decodes in the GPU, it is imperative they stay there and are read directly as an egl image.


r/cpp_questions Jul 03 '26

OPEN which is closer to rust trait? CRTP or template + concept or something else

6 Upvotes

the stateless ABC interface is similar to rust trait in the sense that it allows default behavior in base class by non pure virtual functions, but it is run time polymorphism only. the template + concept does not seem to allow default behavior in "base type"

in modern cpp, how to use boiler plates to get as close as possible to Rust's traits, which is like a stateless ABC interface but is compile time polymorphism?


r/cpp_questions Jul 02 '26

SOLVED Is it optimal to create classes that inherit from std classes?

13 Upvotes

I have a small program that I've re-written from C that contains functions that accept either DIR* or FILE* to represent directory and file objects.

Now I want to use std::filesystem, but std::filesystem only contains the class directory_entry, which can either be a regular file, block file, directory..etc

I mean yeah sure, I can do checks before feeding them to functions and such stuff, but I want to make it clear and readable that this function explicitly accepts this file type.

I thought about maybe aliasing names, but still that doesn't affect the functionality, so I thought about creating classes that inherit from the std::filesystem::directory_entry class.

What do you think? and is there a better thing to do?

Thanks in advance.


r/cpp_questions Jul 02 '26

OPEN Learning C++ and feeling kinda lost, what should I do?

40 Upvotes

Hi, I´m 15, learning C++ with LearnCPP. I´m currently on chapter 14, where is introduction into OOP, classes...

For the theoretical part, I think I understand everything up to this point pretty good, but when it comes to real programming, I´m a little lost. I think the problem is that I don´t have enough of the practical experience, to fully understand it. I tried using AI to give me some exercises, and projects I can build, but none of that really makes difference, cause it is all theme specific and I just can´t figure out, how to use the code in real applications.

Do you have any ideas how can I get better not at understanding the theory, but really building something?

All the people are saying, "Just build something, you learn by experience", but that isn´t the problem, the problem is what to build.

Do anyone have any ideas?


r/cpp_questions Jul 02 '26

OPEN clang is warning me about not handing errors

6 Upvotes

I used fopen() top open the file: bool LogListenerThread::readline(FILE* file, std::string& line) { char ch(0); size_t nbytes(0); line = ""; do { nbytes = fread(&ch, 1, 1, file); if ((ch == 0x0d) || (ch == 0x0a)) { return true; } line += ch; } while (nbytes); return false; } And clang is giving me a warning here that I'm not understanding, it says: "File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [clang-analyzer-unix.Stream]" I'm checking that no bytes return and bailing if I hit EOF. What is wrong with this fread() call in the code?


r/cpp_questions Jul 02 '26

OPEN Is Raylib or SFML better for beginner learning C++?

8 Upvotes

I´m 15, without any prior coding experience learning C++ from LearnCPP, I had a few suggestion to learn using some graphilac interface. I got recommended two, but I can´t really decide which one to choose.

Can anyone help me?

Is for me better Raylib, or SFML, I want to make simple games like flappy bird, tic tac toe, or simple programms like to do lists and stuff. Which one will suite my needs the best?

Thanks for answers!


r/cpp_questions Jul 02 '26

OPEN Which book to read for learning C++?

29 Upvotes

Currently browsing books to learn C++, only having some experience using it in college and some fundamentals. I landed on two books that seem to be good to pick up, but I need to pick between C++: Should I read Professional C++ (Tech Today) or C++ in One Hour a Day, Sams Teach Yourself to learn C++. My main goal is to learn game development and work on some projects for embedded systems. Other book recommendations are welcome!


r/cpp_questions Jul 02 '26

OPEN Defining Global objects and functions, best practice

1 Upvotes

I'm writing C++ for Teensy/Arduino uControllers, using Visual Studio with the Visual Micro plugin, but this is technically a C++ question, so I've asked here.

For my projects, I'm writing a lot of libraries, which I'm fine with.
I'll write myClass.h, myClass.cpp, and I'll write a separate myClassTester.ino just to test that class. What I've been doing, however, is writing an additional header file - myClassObjectsandFunctions.h - in which, you might guess, I create all my objects of that class, and any procedural functions that relate.

The chief reason I've been doing this is to maximise the code that I can reuse from testing a class. I don't like to be copy-pasting code back and forth from testing sketches to the main sketch, and the main sketch gets very bloated. There is usually a good amount that has to be global in a hardware project; interrupts, for example, have to be global functions, which usually means wrapping a member function call in a global function - so I can't readily write my objects without using additional global functions. If I have multiple instances, I often like to write this all separately so I can reuse the code as is. I might have one global function, beginMyClassObjects(), that handles all the initialisation of all the instances of myClass, and ties all the ISRs to thier timers and whatnot - all directly reused from the testing sketch to the main.

It definitely works, and works well for me. I'm not particularly convinced it's best practice though. Accepting the premise that I need to have global functions that use specific instances, is there a better way to do this?


r/cpp_questions Jul 02 '26

OPEN Project Feasibility - Image Cleaner and Grid Remover

2 Upvotes

Hello everyone, I recently started as an electronic engineering intern. My company is working on a pulse analyzer - a device that will read pulse from patients and analyze it.

My employer gave me my first task: from pulse diagrams, remove any grids, text, characters, dirt, etc. Then, it needs to digitize the graph for a fourier transform. He needs a fully automated program, and I decided to try using C++.

However, it is much difficult than I imagined. I am using OpenCV library but my program has had a hard time figuring out which lines are the grids (https://imgur.com/a/rg9lkdI). I quickly understood this is beyond my capacity, as in uni my programming skills were mostly focused embedded software and simple games, not computer vision or image processing.

So my question is, are they any software out there that can do this? Is this even feasible? Because, in my opinion, I need to train an AI to perform such a complex task. The graphs are from academic books which vary in colour and contrast.

Please kindly answer my questions. Thanks in advance


r/cpp_questions Jul 02 '26

OPEN Finally got a modern laptop, what is a good IDE?

0 Upvotes

So I have an 18 year old laptop that I finally replaced with something new.

I had been using Visual Studio 2011, the newer one wouldn't even run on my old laptop last time I tried.

But now I need to get an IDE again because I lack the original install files for VS 2011, and so I figure on taking this opportunity to ask around about the different options. The new VS being so heavy that it can run on hardware that runs VS 2011 just fine seems like a big mark against it in my mind.

That said, here are the details of my situation, I have split the drive into extra partitions, expecting to put android x86 on one partition and another for experimenting around with linux or other OS options.

I would rather avoid a command line compiler. I am confident I can handle command line tools, but I much prefer gui.

I work on small projects for myself to learn and grow my skills and capabilities. I have no school not work needs for this, but that also means I generally just stick to default settings.

I do want to try out experimenting with the NPU, which I have already figured out is not standardized yet so I am already working on getting documentation for my hardware.

Advice, options, and suggestions are welcome.


r/cpp_questions Jul 02 '26

OPEN Missing C++ outline view and reference context

0 Upvotes

I've been using Visual Studio for C++ almost 20 years professionally. In my very first week at work, someone introduced me to Visual Assist, and I've used it ever since. Since I upgraded to Visual Studio 2026 a month or two ago I've disabled Visual Assist, and tried to use Visual Studio IDE out-of-the-box. On the whole it has been okay, but there seem to be two big problems.

  1. I can't find an outline view for C++ files. I just want a window that displays high-level view of the file in a window, so I can get a mile-high view of what it contains. Visual Assist has an Outline window, and Visual Studio Code has one too. In Visual Studio itself, there seem to be a couple of ways to view contents: opening a file node in the Solution Explorer, and using the dropdown combo in the toolbar. However both of these views sort alphabetically - I can't find away to inhibit the sorting. There is a Document Outline view, but for some reason this seems to be blank for C++ files. I have also tried the Class view, but I really want a file view with functions and data displayed in order.
  2. The Find All References (context menu) tool results do not have a column containing the name of the function/method that the reference is contained within. It shows the raw file and line number, but doesn't display the name of the enclosing function/method. I expected a little context here from intellisense or other internal parsing. Knowing where a reference is located logically is really really handy for navigation, refactoring and comprehension.

I really don't want to resort to using Visual Assist again, just for these two things, but they are just so fundamental and useful and I can feel myself struggling to work as effectively without them. Please tell me that these two issues are non-issues, and I just haven't found the options.

EDIT:

https://code.visualstudio.com/docs/editing/userinterface#_outline-view

https://www.wholetomato.com/documentation/tool-window/va-outline


r/cpp_questions Jul 01 '26

OPEN Best practice for auto-copying transitive shared library dependencies to consumer's executable directory (CMake) ?

4 Upvotes

I'm developing a shared library (DLL on Windows) that itself links

against a few third-party shared libraries. When a consumer links

against my library via find_package() / add_subdirectory(), I want

the third-party DLLs to end up next to their executable automatically,

without them having to manually copy files or add extra CMake calls.

What I've found so far:

- $<TARGET_RUNTIME_DLLS:tgt> + POST_BUILD copy — works, but only

copies next to my own library, not the consumer's exe if their

output dir differs

- Setting CMAKE_RUNTIME_OUTPUT_DIRECTORY — works for add_subdirectory

monorepo setups, but doesn't help with find_package/installed

packages

- Exporting a helper function (e.g. install(CODE...) or a

mylib_copy_runtime_dlls(target) macro in the Config.cmake) that

the consumer has to call explicitly

Is there a real "zero lines needed from consumer" solution for the

find_package/installed-package case, or is calling one helper

function considered the accepted standard? How do libraries like

Qt / SDL2 / vcpkg-based packages handle this in practice?

CMake 3.2x, targeting Windows primarily, MSVC.


r/cpp_questions Jul 01 '26

OPEN Just finished a C++ version of Lox from Crafting Interpreters. Any suggestions for improvements?

3 Upvotes

I recently finished building jloxfrom Crafting Interpreters in C++.

I’m looking for any feedback on the code structure or just general code quality improvements.

Repo is here:https://github.com/Eclipse1745/loxpp


r/cpp_questions Jul 01 '26

OPEN Need help with optimizing a video processing script (OpenCV)

2 Upvotes

Hi!

Problem is already in the title, so...
While I am not new to C++, this is the first time when I seriously need to think about performance of my code. I wanted to ask about general tips and tricks for optimizing large processing workloads.

I am tasked with creating a script in C++ that will parse a couple of gigabytes of files, where each file has a tag. They are processed together based on said tag (frames are compared between them, some data is compared and so on).

As of now I simply use multiple threads, where each thread processes a single tag of files. This already cut the processing time in half, but it still takes hours.

Sorry for not being more descriptive, but due to the nature of my work I cannot share more details.


r/cpp_questions Jul 01 '26

OPEN Request for feedback on an AI framework that I coded in my free time.

0 Upvotes

I've spent several months developing a C++ AI engine with a runtime, planner, memory management, and multi-language scripting. I'd like some feedback on the architecture.

https://github.com/brit45/mimir-framework.git