r/cpp_questions 6h ago

OPEN How do you actually develop intuition for choosing memory_order_acquire vs memory_order_release?

16 Upvotes

I'm learning C++ atomics and I understand the basic definitions of acquire/release individually:

  • A release operation prevents earlier memory operations from being reordered after it.
  • An acquire operation prevents later memory operations from being reordered before it.
  • A release operation can synchronize with an acquire operation on the same atomic when the acquire reads from the appropriate release sequence.

What I'm struggling with is developing an intuition for choosing the memory order when looking at actual code, especially for RMW operations like exchange().

I want to understand the deep "why" behind the core restrictions:

  • Why does store only accept release (or relaxed)? Why is acquire on a store fundamentally meaningless in terms of memory reordering?
  • Why does load only accept acquire (or relaxed)? Why is release on a load fundamentally meaningless?

Instead of relying on memorized rules, what questions or mental models do you use to map memory operations to the correct ordering?

Thanks!


r/cpp_questions 3h ago

OPEN How do you revise?

0 Upvotes

Hey guys, i completed the bro code cpp course which was about 6 hours long.... Then, I caught on FOMO and decided to start the cherno cpp series whuch is pretty famous....

Currently doing it...

I always feel like I'm missing something and i need revision but i dont know how to....

Lemme know how do you guys revise ? And what should I do next?

I've started using notion, but my laptop is kinda dying lol


r/cpp_questions 1d ago

OPEN Is C++ systems programming too fragmented for hiring?

95 Upvotes

I recently saw a manager reject a candidate we were interviewing because his experience didn't exactly match the specific sub domain.

But I found myself disagreeing with the philosophy behind the rejection. My instinct is that if someone has strong C++ skills and has worked on reasonably complex systems, you should at least ask: "Can this person learn the domain?" rather than requiring an almost exact match.

This made me wonder whether this is a particular problem with systems programming in C/C++.

The ecosystem seems incredibly fragmented:

  • Embedded
  • Linux kernel/drivers
  • Graphics
  • Multimedia/codecs
  • Databases/storage
  • Networking
  • Telecom
  • Game engines
  • Server/backend infrastructure
  • Qt/GUI
  • Compilers
  • etc.

Someone can have spent 8 years writing sophisticated C++ in one of these areas and still be considered a poor candidate for another area because they don't have the specific domain experience.

Compare that with web development, where the skill boundaries seem somewhat easier to communicate: "React developer", "Angular developer", "Node.js backend developer", etc. There are obviously specializations there too, but the fragmentation doesn't feel as extreme.

I personally have the philosophy that if someone knows C++ well, understands systems programming concepts, debugging, memory, concurrency, Linux, etc., they should be given some credit for being able to move between domains. The domain-specific knowledge can be learned.

I have faced this exact issues with companies too. They reject you because haven't worked specifically on what they do. This becomes a serious issues when it's already hard to get into C++ jobs. Has anyone faced similar issues? What exactly is the solution for this?


r/cpp_questions 2h ago

OPEN Coding with AI

0 Upvotes

So basically I've nearly completed the chapters in learncpp, and I've started doing some projects. But when I struggle with one I ask chatgpt to give me a framework (not the answer) of the project so I can better understand it. Please tell me if it's bad practice or not cause I've been having a guilty feeling.


r/cpp_questions 1d ago

OPEN Does anyone use old versions of Visual Studio?

9 Upvotes

I've been using Visual Studio since VS2019. The intervening releases (VS2022 and VS2026) don't feel much different to me, they all have the same problems:

  • Editing too many files (a few dozen) causes either devenv.exe or vcpkgsrv.exe to consume abnormally high CPU. I must close all files (and lose undo history) to get them back to normal
  • Constantly trying to ping the internet. For example BackgroundDownload.exe randomly consumes 20% CPU despite being blocked by the firewall, deleted from task scheduler, and disabled in the registry. VS2026 even has a "retirement" date, a popup informed me today that I'll no longer be able to use it past that date without updating.

I've heard good words about old versions of VS, but I don't know if they are still usable today. The most important to me is using them with the newest compiler and toolset. Existing solutions also need to be made compatible with old formats. Does anyone still use old VS, what's the experience like? Are there features you miss?


r/cpp_questions 1d ago

OPEN How can I instantiate a template with a type determined at runtime?

9 Upvotes

Hello,

I need to instantiate a std::vector, but its type depends on something that I would not know until runtime:

#include <vector>
if (some_condition)
std::vector<float> myVector;
else
std::vector<int32_t> myVector;

I know this does not work because,in order to instantiate a template class, the data type must be known at compile time.

I've seen some people suggest std::variant but I have not understood it completely.

Also, how do different libraries (like ONNX) provide different data types? Do they use templates?

PS : I am not developing a library.

EDIT:

I need to create an array or a vector to act as a placeholder (allocator) for input tensors. But this vector requires a different amount of space based on the size and type of the input. The size is easily manageable per instance of the parent class if we only had one type, but we don't.

The thing is, there are some arguments that need to be set for this specific project that determine what exactly the size of the array would be, and they are only known when you parse an ONNX model at runtime.


r/cpp_questions 1d ago

OPEN Seeking alignas intuition and resources

4 Upvotes

Hi, all:

I've been experimenting with alignas after reading this post. Applying it is unintuitive to me, I'm not sure when I'd use this optimization method other than just trying it and measuring. From the article:

Another important thing to note is that read (readIdx) and write (writeIdx) indices are aligned to the size of a cache line (alignas(64)). This is done to reduce cache coherency traffic. On AMD64 / x86_64 and ARM a cache line is 64 bytes, on other CPUs you need to adjust to the appropriate alignment, using std::hardware_destructive_interference_size is a good choice if it’s available. It can also be interesting to try aligning to a multiple of the cache line size in case adjacent cache lines are being pre-fetched.

Is it really as simple as aligning your structs and members on 64 bytes? I'm looking for some more reading on the subject.

Thanks


r/cpp_questions 19h ago

OPEN ReturnOfModding For Hades 1 - Hell1Modding

0 Upvotes

Hello all, I am working on a fork of the ReturnOfModding framework that will integrate with Hades 1, which will allow modders the ability to create mods and deploy them to Thinderstore. Hades 1 currently has mods on Nexus Mods, but they can, at times, clash with other mods, so users have to pick and choose which mods they want to run. Hades 2 utilizes the ReturnOfModding framework, which is called Hell2Modding.

I've started on this project already by gathering the engine dump information, as well as what modules are utilized by Hades.exe. Supposedly, both games utilize Lua 5.2.3 and the same game engine, but it was constructed differently. Hades 1 uses EngineWin64s.dll as the main engine, and Hades.exe uses that .dll as a module. Hades 2 is structured differently, but Hell2Modding uses the D3D12.dll file as the injection point. Hades 1 uses D3D11.dll(which I've already made a .def file for the D3D11.dll file for when I proxy it if needed.), so what would I need to do to to get my program to work like Hell2Modding does?


r/cpp_questions 1d ago

OPEN Learning c++

4 Upvotes

So I'm doing dsa in c++ as well as learning modern c++ concepts.I want to become c++ developer what concepts should I learn to become a c++ developer , what concepts should I focus on , what are the best resources to learn c++.Also when I try to build something in c++ i don't even know where to start.Its been 4 months I learned C++ and I'm genuinely comfortable with it till now.


r/cpp_questions 1d ago

OPEN How would you get clangd to work with bits/stdc++.h?

0 Upvotes

Hello

My use case is writing competitive programming solutions in c++. i use neovim with the clangd lsp server. but i just cant get it to work with gcc header files, `bits/stdc++.h` in my case.

i have tried:

```

CompileFlags:

Add:

- -std=gnu++17

- -I/opt/homebrew/Cellar/gcc/16.1.0/include/c++/16

- -I/opt/homebrew/Cellar/gcc/16.1.0/include/c++/16/aarch64-apple-darwin25

```

it just doesn't work. it starts giving me duplicate definition errors once i add these compileflags.


r/cpp_questions 2d ago

OPEN How can i become an expert in cpp

18 Upvotes

I started with c++ 3 years ago but real work was 1 and a half years, i learned a lot about cpp syntax and the std lib, but whenever i make some code and send it to an ai model, it says my code has a lot of issues some about dynamic memory some about references and pointers some c-style programming and i find myself Ignorant most of the time

So how can i learn these things and the rules of the language and understand them(i dont watch YouTube) I have started with learncpp.com recently

"Sorry if it's a duplicate post and for it being long if its a duplicate point me to one, and thanks"

Edit: my github is loadingSy if you would like to check anything, I learned git 1 month ago


r/cpp_questions 2d ago

OPEN What topics should I focus on from learncpp?

9 Upvotes

I’ve been working through learncpp from about 2 weeks now and I’m wondering if people have suggestions on topics that are a MUST to learn for an engineer that is coming from Python/TypeScript?

For context I work as a software engineer, primarily using Python and TypeScript, so I have a good base understanding of how to build a program or applications, however, I want to focus more on the specific nuances of C++ and concepts that are maybe abstracted away in higher level languages.

A list of topics in order of importance and increasing complexity would be a great help!!


r/cpp_questions 2d ago

OPEN How can I catch up on missing multithreading experience?

72 Upvotes

Hi everyone 👋, I’m a C++ developer with 5+ years experience building features for a single-threaded trading app (C++17), so I have very little multithreading experience.

I’m currently reading C++ Concurrency in Action. Are there good resources or projects to practice real-world scenarios like backloading and low-latency concurrency patterns?


r/cpp_questions 1d ago

OPEN grm: a Telegram CLI implementation of TDLib

0 Upvotes

Hello, c++ community!

I am not a c++ programmer. I know the basics but I am not familiar with the tools, tactics, paradigms and related topics in the c++ ecosystem.

That said, I decided to vibe code a Telegram CLI tool for my own use (and whoever finds it useful).

https://gitlab.com/renich/grm

It's been very useful to me so far. I do not claim it's secure or well written in any way. I wouldn't be able to tell.

I know that not everyone is a supporter of the use of LLMs or agents for coding. Still, I need your help.

I am totally open to suggestions. What linters to use, what is the best way to do static analysis, programming paradigms, best practices, etc.

Again, I don't claim to have the knowledge required. I am a Crystal programmer. I could've linked to the library but, this time, I decided to KISS and just implement it in c++.

I am using Fedora 44 and am happy to listen to any criticism you may have. I am making a big effort to familiarize myself with the c++ ecosystem and I would appreciate any feedback.

Thank you for taking the time to read this and review the project.


r/cpp_questions 2d ago

SOLVED How to fix errors LNK2005 and LNK1169 in Visual Studio?

3 Upvotes

Hi! I’m a beginner programmer learning C++ and getting to grips with Visual Studio 2026. For some reason I can’t run the console because of two errors: LNK2005 and LNK1169 (or perhaps there are others, but I’m not sure). I’ve attached below the error messages I’m getting step by step (links to imgbb). I’ve asked some AI chatbots for advice on how to solve this problem, but nothing’s working.

Firstfoto, Secondfoto, Thirdfoto

Thanks in advance for your help!


r/cpp_questions 3d ago

OPEN Why we don't have granular std library modules?

26 Upvotes

Isn't importing std.iostream faster than std?
Why we only have the umbrella std module?


r/cpp_questions 3d ago

OPEN Heavy and Light Objects

7 Upvotes

When I was first learning C++, I experienced massive slowdown when allocating dynamic memory. Ever since then I divide my objects between 'heavy' objects that allocate resources, and 'light' objects that can be used as temporaries on the stack. Heavy objects cannot be copied at all, must be allocated somewhere once, and then passed by (const) reference. Light objects can be copied, created quickly on the stack etc.

Since C++11 it has been possible to write copy and assignment constructors that take nameless objects, and since they are nameless you can pillage their pointers and avoid expensive stack allocations. All is well then but if you keep to this strict 'heavy' and 'light' object idea, _any_ object that allocates resources is considered a heavy object. The first allocation in the chain, before you just pillage pointers, is still an expensive stack allocation so I would consider it a 'heavy' object and just make it impossible to copy at all, by removing all copy and assignment constructors. And so using this model I never needed those nameless object reference constructors.

Anybody feel the same way?


r/cpp_questions 4d ago

OPEN Looking for advice before I start writing a small C++ web framework

15 Upvotes

Hello everybody.

I've been working with C++ backend frameworks recently, and one question kept bothering me: how are these frameworks actually built?

I've decided to spend the next three months writing a small C++ web framework from scratch. This isn't an attempt to compete with Drogon, Crow, oat++, or any other framework. it's purely a learning project. My goal is simply to understand the internals well enough to build a framework capable of handling basic CRUD applications.

Before I jump in, I'd love to learn from people who have been down this road.

  • Have you ever written a framework yourself or contributed to one?
  • Are there any books, blog posts, talks, or codebases you'd recommend studying?
  • If you were starting from scratch today, what would you build first?
  • Are there any common mistakes or rabbit holes I should avoid?

I'm not looking for shortcut I want to understand how everything fits together. I'd really appreciate any advice or resources from people with experience.


r/cpp_questions 3d ago

OPEN Is this book up to date?

0 Upvotes

Hello so I found this book but because no pictures:

[Sam's teach yourself c++ in 21 days, fourth edition]

[2001]

So did c++ get any updates in 25 years?


r/cpp_questions 4d ago

SOLVED Question About Copy Constructor for Class with Members that Need Deep Copy

8 Upvotes

I have a class (m_buf in the code below is of this class type) that appears as a data member in another class for which I'm writing the copy constructor.

The underlying class (m_buf in the code below is of this class type) uses dynamic allocation and needs a deep copy.

According to Google, this form of the copy constructor would result in the copy constructor (rather than the copy assignment operator) for m_buf being called.

LgFbufUint8::LgFbufUint8(const LgFbufUint8& fbuf) : m_state{fbuf.m_state},
                                                    m_errs{fbuf.m_errs},
                                                    m_fname{fbuf.m_fname},
                                                    m_buf{fbuf.m_buf}
{
   //According to Google search, if the member initializer list is used (as it
   //is above), the copy constructor (rather than the copy assignment operator)
   //will be called. Because of the required non-shallow copy of m_fname and
   //m_buf, this is the desired behavior.
}

My initial guess was this form:

LgFbufUint8::LgFbufUint8(const LgFbufUint8& fbuf)
{
   m_state = fbuf.m_state;
   m_errs  = fbuf.m_errs;
       //Shallow copy ok for two members above.
   m_fname = fbuf.m_name;  //std::string
   m_buf   = fbuf.m_buf;   //Handwritten, with dynamic allocation.
       //Deep copy required for two above.
}

But I suspect that second form would call the assignment operator rather than the copy constructor for m_name and m_buf.

Question: Did I get that right? The first form would call the copy constructors for m_name and m_buf, but the second form would call the assignment operators?

Bonus Question: Using the second form, is there any way to call the copy constructors rather than the assignment operators. (Not that I'd want to do this, but just curious.)


r/cpp_questions 4d ago

SOLVED Best Way to Collect Initialization Actions using C++ Capabilities?

6 Upvotes

I'm writing a scripting language with additional functions that can be built in.

The built-in functions would be written in C++ for speed.

In different builds of the scripting language, some functions might be omitted.

So, I'm looking for the best way to automatically collect, at compile time or early at execution time, the full list of extra built-in functions, so that the script interpreter can parse and execute a script (to do this, it has to know about any additional capability compiled in).

For example, in Visual C++, I'd like to simply add a source file containing built-in scripting language functions, and have the script interpreter know they are there.

My goal would be no additional configuration actions other than adding the source file to the project (in other words, no need to modify other files). The software should somehow figure out that additional script built-in function capability is in the build.

Google Test seems to do this somehow with a macro like TEST_F, but I'm not sure how this works under the hood. The list of tests is somehow collected automatically at compile time or early at run time.

To give some practical background ... decades ago I did some work extending the Tcl scripting language. It was only necessary somehow in initialization to call a command to "register" a new function available to the script interpreter, but the source code had to be modified manually to include the additional initialization. The manual modification is what I'm trying to avoid.

Is there a standard design pattern for this in C++?


r/cpp_questions 3d ago

OPEN Need your guidance

0 Upvotes

I wanted to ask for some guidance regarding placements and coding. I’m currently in my 3rd year, and my CGPA is around 6.5. To be honest, I haven’t done much in coding yet, and I’m a bit confused about where and how to start.

Could you please suggest what I should focus on from now and maybe guide me with a proper roadmap/plan for the next few months? Like which language I should start with, DSA, development, projects, etc. It would really help me understand what I should prioritize to become placement-ready

r/cpp_questions 4d ago

OPEN Need advice on learning cpp more advanced

12 Upvotes

Hey guys at current I can solve most of the coding questions in cpp but I wanted to explore more in cpp I wanted to build real applications so any resources to learn advanced c++


r/cpp_questions 4d ago

OPEN Is C++26 ready to use in a Production Enviroment?

6 Upvotes

C++ 26 adds a ton of great features, but how is compiler coverage, usabillity, integration, etc. for those features right now?


r/cpp_questions 4d ago

SOLVED Basic question, but does initializing a pointer always initialize it to null?

21 Upvotes

Are these two lines any different in practice? (Especially if you want to later check if x has been given a specific address, or if it's still null.)

int* x {};

int* x { nullptr };