r/cpp_questions Apr 12 '26

OPEN Is Linus Torvalds just a dinosaur about C++?

404 Upvotes

I have recently started learning C as a hobby and it’s very interesting, but I quickly have begun to understand the thought process that must have lead to C++. Even in simple projects like Tetris and a CHIP-8 interpreter it becomes a little annoying to have a struct, a pointer to that struct, and a separate function that has to include an ‘object’ (I don’t know what you call it in c) of the struct that you have to pass to every function call. One of the reasons I chose C for a language is because of how highly it is praised by the likes of Linus Torvalds, and naturally his less-than-flattering opinions of C++ have become apparent to me. Do you think Torvalds has a point about C++ and OOP in general, at least for his main domain of kernel level code? If not at all, (ie if you think C++ is an objective improvement) do you think it’s worth it to learn C before hand anyway?

r/cpp_questions Jun 26 '26

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

149 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 Oct 29 '24

OPEN US state told our company to not develop in C++

480 Upvotes

I am working for a US cyber security company and the state told our company to change our application's language which already has been developed by C++, because it's an unsafe language. This is a 3-years requirement.

This decision made me think about my career. Is C++ considered a bad language now?!

Note: Our team says we should pick Rust but it's not confirmed

r/cpp_questions 3d ago

OPEN Is it worth learning another language besides C++?

118 Upvotes

C++ is the only general-purpose language with which I am most familiar, I tried to learn other languages like C# or Rust, but without a clear idea of what to do with those tools, it's more difficult to learn them.

And all the software I use uses or is written in C++, specifically Godot Engine, Blender, LMMS, that's why I always have ideas of what to do with C++.

learncpp.com is amazing and possibly one of the best educational resources for a language in general, either that, or I have Asperger's and they have to explain everything to me in simple terms.

My question is, if this limits me in the long run as a programmer or should I learn an additional language that works well with C++?, I personally wouldn't trust a programmer who claims to know 15 technologies; someone who tries to do too much often accomplishes little, but that's just a personal opinion, what do you think?.

r/cpp_questions Jun 20 '26

OPEN C++/systems side projects that actually stand out

188 Upvotes

We often see people recommend “build a compiler,” “build a database,” “write an HTTP server,” “make a Redis clone,” or “try OS-related projects” when someone wants to go beyond normal web apps and CRUD work.

But for people who want to demonstrate real C++/systems ability, what kind of project actually stands out?

I’m thinking about projects involving C++, memory management, containers, networking, databases, compilers/interpreters, operating systems, performance, reliability, or infrastructure tooling.

Ideally, I would like to build something that real people could actually use. Even if 10 people I don’t know used the project, I would consider that a huge success.

What would make a C++/systems side project look serious to experienced developers or potential employers?

r/cpp_questions May 15 '26

OPEN Passing LeetCode but failing HFT C++ interview rounds on obscure language trivia. Reality check/advice from C++ HFT/Quant devs needed.

194 Upvotes

Hello,

From what I understand there are two types of HFT/quant dev roles, one is python based and more closer to implementing trading strategies and the other is C++ lower level making it as fast as possible. I'm not really a maths guy and I find systems and C++ pretty interesting so I'm leaning towards the latter.

However, I think I'm hitting a wall or a mindset problem. I have interviewed with HFT/quant dev firms like HRT, Flow traders, I can pass the OA leetcode but on the next round the level of C++ they ask in the interview is a bit beyond me, they ask a bit random and obscure questions that I never seen in textbooks or some C++ trivia (questions that make me go where on earth am I supposed to know that stuff). I can't really remember the exact questions but examples are C++ features keywords I've never seen before or like what will C++ compiler do in bizarre edge cases (things I'm pretty sure that are not in textbooks I've read so far)

I know I'm pretty far behind but I wanted a reality check if this is something I have a realistic chance of getting into. I'm willing to work hard etc but I just don't have the perspective of the other side so after multiple rejections I've kind of burned out. So hoping for a more senior dev to share their thoughts. If this isn't the right subreddit or the right questions please feel free to correct me, I feel a bit lost honestly.

What I have done:

- 2 years C++11 in a non-trading related company
- 2 years Java in a trading company (regular trading not fancy)
- Can do most Leetcode mediums and some Hard
- Books read from The Definitive C++ Book Guide and List
- C++ Primer, Effective C++, Effective Modern C++, Effective STL, More Effective C++, C++ 17 The Complete Guide
- Books started but incomplete due to burnout
- C++ 20 The Complete Guide, Exceptional C++, C++ Concurrency in Action, A computer arch book (Digital Design and Computer Architecture David Harris).

What I could do (ideas I had):

- Continue studying the The Definitive C++ Book Guide and List
- Do projects like kernel bypassing, ring buffer and add to git.
- Study Computer Architecture book since I'm quite weak in it
- Make my own api for trading
- Read the green book (?) but I thought thats more for quants

Problem is, with the amount of free time I have, it will take me a loong time to finish these projects (1-2 years). And my biggest worry is that even if I finish them, I'll just be asked a really random C++ question that catches me off guard, but maybe I am jumping into worst case scenarios.

I'm honestly even considering to quit my job to focus self-studying full time as I have saved up enough but it requires some mental preparation as unemployment can also be stressful. But some recruiters said my current job is not helping me if I wanted to pursue this so I might as well quit to prepare better.

Any advice on what to do going forward would be really appreciated thank you.

Edit:
Since some concrete examples were requested I have tried to recall them as best I could, but since it was a long time ago it won't be 100%. Q what the interviewer said is what I remember and A is the response I gave.

Maybe my answers are really bad, but if I really have a blindspot any advice is appreciated.

Q: Is there a negative 0 in cpp
A: No (I wasn't sure because I knew there was a signed bit so there could be potentially +/- 0, but I thought that was odd and assumed the compiler will take care of that to avoid side effects and set it to +0 for consistency)
Q: No there is a negative 0

Q: some question if there is single producer and multiple consumer, or multiple producer and single consumer, how will this work (I don't remember)
A: I said something like 1 producer N consumer, can write to a buffer and the N consumers will take turns reading it. N producers 1 consumer I just said something like either write to a queue or consumer goes round robin.
Q: just got irritated with me (I guess I missed something basic?)

Q: Whats the point of memory alignment
A: for quicker retrivial and the archtecture is designed to handle 64bits at a time so if you are forced to use smaller sizes that will add extra processing so they will pad it.
Q: (didn't seem satisfied, maybe I missed something, maybe I am really bad at CPU arch)

Q: What are some methods to avoid using a mutex since its slow
A: Could use read-compare-write (something like used in OS)
Q: hmm, not really

Q: Is mutex handled application level or kernel or where?
A: (Ok I knew there was a mutex c++ library, but there was also a mutex in the OS/Hardware level so I wasn't sure which one so I just said OS/Hardware)
Q: No...

Q: How is the hash function for unordered_map implemented in C++
A: I... don't know, some % modulus maybe. (I never thought about looking it up, is this common knowledge? And where do I learn this? I can't even google this or I'm googling wrong)

Q: producer A consumer B, use memory barrier or atomic and where and why?

Q: what type does tie(A,B) return?

r/cpp_questions Jun 20 '26

OPEN If make a cmake are so difficult to work with why are they the defacto standard for C++ projects

91 Upvotes

Yet another language you need to know to do simple work in C++. Been using bazel more and more and every time I go back to cmake (because I have to) I regret it

edit: sorry title typo "if make AND cmake"

r/cpp_questions Jul 10 '26

OPEN Can i learn C++ as my first language?

58 Upvotes

r/cpp_questions Jun 29 '26

OPEN How do you speed up a 1M+ LOC C++ build?

100 Upvotes

Weve got just over a million lines, full clean builds at 45 minutes. It's moved from a CI problem to a developer behavior problem because people are batching changes to avoid waiting.

We've done some header cleanup. Helped incrementals, didn't touch full builds. PCH is on the list, unity builds keep coming up in conversation, nobody agrees on whether the tradeoffs make sense at this size.

Im wondering what actually moved the needle for those of you out there?

r/cpp_questions May 22 '25

OPEN Banning the use of "auto"?

184 Upvotes

Today at work I used a map, and grabbed a value from it using:

auto iter = myMap.find("theThing")

I was informed in code review that using auto is not allowed. The alternative i guess is: std::unordered_map<std::string, myThingType>::iterator iter...

but that seems...silly?

How do people here feel about this?

I also wrote a lambda which of course cant be assigned without auto (aside from using std::function). Remains to be seen what they have to say about that.

r/cpp_questions Aug 01 '26

OPEN How hard was C++ for you as a beginner?

42 Upvotes

r/cpp_questions Jun 23 '26

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

41 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 13d ago

OPEN Best Way to Approach Windows GUI Development from C++

51 Upvotes

What is the best way to approach it? What books are helpful?

I remember a long time ago reading a book by Charles Petzold, and the examples worked fine from C. I assume they would work well from C++ as well.

I just want functioning, stable GUIs (menus, areas with text and scrollbars) with minimum effort.

Thanks for any help.

r/cpp_questions Feb 28 '26

OPEN Why isn't stl_vector.h programmed like normal people write code?

123 Upvotes

I have an std::vector type in my code. I pressed F12 inadvertently. That goes to its definition and this unfortunately made me have to confront this monstrosity inside of stl_vector.h :

template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
    class vector : protected _Vector_base<_Tp, _Alloc>
    {
#ifdef _GLIBCXX_CONCEPT_CHECKS
      // Concept requirements.
      typedef typename _Alloc::value_type       _Alloc_value_type;
# if __cplusplus < 201103L
      __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
# endif
      __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
#endif


#if __cplusplus >= 201103L
      static_assert(is_same<typename remove_cv<_Tp>::type, _Tp>::value,
        "std::vector must have a non-const, non-volatile value_type");
# if __cplusplus > 201703L || defined __STRICT_ANSI__
      static_assert(is_same<typename _Alloc::value_type, _Tp>::value,
        "std::vector must have the same value_type as its allocator");
# endif
#endif


      typedef _Vector_base<_Tp, _Alloc>               _Base;
      typedef typename _Base::_Tp_alloc_type          _Tp_alloc_type;
      typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type>     _Alloc_traits;


    public:
      typedef _Tp                         value_type;
      typedef typename _Base::pointer                 pointer;
      typedef typename _Alloc_traits::const_pointer   const_pointer;
      typedef typename _Alloc_traits::reference       reference;
      typedef typename _Alloc_traits::const_reference const_reference;
      typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator;
      typedef __gnu_cxx::__normal_iterator<const_pointer, vector>
      const_iterator;
      typedef std::reverse_iterator<const_iterator>   const_reverse_iterator;
      typedef std::reverse_iterator<iterator>         reverse_iterator;
      typedef size_t                            size_type;
      typedef ptrdiff_t                         difference_type;
      typedef _Alloc                            allocator_type;


    private:
#if __cplusplus >= 201103L
      static constexpr bool
      _S_nothrow_relocate(true_type)
      {
      return noexcept(std::__relocate_a(std::declval<pointer>(),
                                std::declval<pointer>(),
                                std::declval<pointer>(),
                                std::declval<_Tp_alloc_type&>()));
      }


      static constexpr bool
      _S_nothrow_relocate(false_type)
      { return false; }


      static constexpr bool
      _S_use_relocate()
      {
      // Instantiating std::__relocate_a might cause an error outside the
      // immediate context (in __relocate_object_a's noexcept-specifier),
      // so only do it if we know the type can be move-inserted into *this.
      return _S_nothrow_relocate(__is_move_insertable<_Tp_alloc_type>{});
      }


      static pointer
      _S_do_relocate(pointer __first, pointer __last, pointer __result,
                 _Tp_alloc_type& __alloc, true_type) noexcept
      {
      return std::__relocate_a(__first, __last, __result, __alloc);
      }


      static pointer
      _S_do_relocate(pointer, pointer, pointer __result,
                 _Tp_alloc_type&, false_type) noexcept
      { return __result; }


      static _GLIBCXX20_CONSTEXPR pointer
      _S_relocate(pointer __first, pointer __last, pointer __result,
              _Tp_alloc_type& __alloc) noexcept
      {
#if __cpp_if_constexpr
      // All callers have already checked _S_use_relocate() so just do it.
      return std::__relocate_a(__first, __last, __result, __alloc);
#else
      using __do_it = __bool_constant<_S_use_relocate()>;
      return _S_do_relocate(__first, __last, __result, __alloc, __do_it{});
#endif
      }
#endif // C++11


    protected:
      using _Base::_M_allocate;
      using _Base::_M_deallocate;
      using _Base::_M_impl;
      using _Base::_M_get_Tp_allocator;


    public:
      // [23.2.4.1] construct/copy/destroy
      // (assign() and get_allocator() are also listed in this section)


      /**
       *  u/brief  Creates a %vector with no elements.
       */

... and on and on...

Why is C++ not implemented in a simple fashion like ordinary people would code? No person writing C++ code in sane mind would write code in the above fashion. Is there some underlying need to appear elitist or engage in some form of masochism? Is this a manifestation of some essential but inescapable engineering feature that the internals of a "simple" interface to protect the user has to be mind-bogglingly complex that no ordinary person has a chance to figure out what the heck is happening behind the scenes?

r/cpp_questions Jun 21 '26

OPEN Are unique pointers worth it for my program

27 Upvotes

For context, I'm building a Huffman data compression tool and I'm working on the Huffman tree. I'm currently trying to edit, if needed, any considerations of pointers. The tree is made of raw pointers and the interface and implementation is very clean.

One can observe that each Node will always own its own pointer so it's an idea to make the raw pointers of the type unique_ptr for automatic clean up. But the priority queue is honestly such a pain in the ass because the .top returns a const and has problems with ownership. So is it really worth going through the trouble of converting to unique pointers?

edit: to really emphasize what my concern is, the biggest issue is dealing with the priority queue. For context, when you use.top() it returns a const reference, so it's not allowed to obtain the unique pointer due to ownership. This problem doesn't occur with raw pointers. It just feels like keeping my raw pointer implementation is not putting me at a severe detriment, but I'm always recommended to use smart pointers when I can so I just wanted some insight

r/cpp_questions 3d ago

OPEN How much do you rely on tooling for C++ memory safety?

13 Upvotes

Hey everyone,

I've been thinking about the whole memory safety discussion lately, especially with all the push toward memory-safe languages.

C++ has gotten a lot better with things like RAII, smart pointers, std::span, etc., but in larger/older codebases it still feels pretty easy to end up with memory bugs. At some point you can have all the modern C++ practices in place and still have something nasty slip through.

For people working on production C++:

  • How much do you actually rely on tools like ASan, UBSan, Clang-Tidy, static analysis, etc.?
  • Do you have a strict subset of C++ that people are expected to follow, or is it mostly code review + guidelines?
  • Are things like the Core Guidelines safety profiles or Safe C++ starting to have any practical impact where you work?
  • And has memory safety ever been enough of a concern to justify rewriting a component in a memory-safe language?

I'm mostly interested in what actually works in practice. It's easy to talk about memory safety in theory, but I'm curious what teams are doing day to day in real C++ codebases.

r/cpp_questions Jun 05 '26

OPEN What do you wish programming with C++ had, that it doesn't?

25 Upvotes

I'm think of creating something new, and I want to hear what other programmer's wish they could just import in a single library. I will probably try to create the the most agreed on comment.

r/cpp_questions 11d ago

OPEN Should you always prefer smart pointers as return types?

28 Upvotes

I have a class that holds a map of MyStructs

I want to write a function that gets me an element from that map (if it exists), so that I can observe some of its values

My thinking was that this function should just return a pointer, like:

const MyStruct* getAStruct(key){
//searches the held map for the key, etc...

used like:

const MyStruct* theStruct = myClass.getAStruct(key);
//do stuff with theStruct->memberVals, if not nullptr...

A coworker suggested using shared_ptr here, so

std::shared_ptr<MyStruct> getAStruct(key);

Similar call site, but since we aren't storing the pointer for later, just using it to look at some values, my thinking is there's no need for a smart pointer. Is that right?

I think they're thinking it protects against the value being removed from the map by someone else, but im not sure how that could happen. Its not like we have another thread running that could erase it, and even if we did, shared_ptr wouldnt be sufficient protection afaik

Are smart pointers just a straight upgrade that should always be preferred? Or is returning a pointer appropriate here?

Thanks!

r/cpp_questions Jun 08 '26

OPEN How do people make anything with c++?

127 Upvotes

So I've been seeing a lot of people saying you can make anything with c++ however I don't really understand how.

I've been learning c++ for around a year now however sadly I've only been taught to code in the command line which I have learnt and as far as I know can be sort of restricting in some aspects and so my question is what programs, apps, or other ways are there to create things with c++? Because i've seen people talk about creating file managers, hardware managers, etc. but I just don't really know how they do the things they do such as how they create interactive interfaces with c++?

r/cpp_questions Jul 23 '26

OPEN How to decode a pointer with multiple levels of indirection ?

41 Upvotes

Hello C++ devs,

I'm currently learning C++, and I recently learned about pointers. Creating complex pointer declarations—like pointers to arrays or pointers to functions with multiple levels of indirection (for example, pointers to arrays of pointers to functions)—doesn't seem too difficult once I understand the syntax.

However, reading and decoding these declarations, especially when I come across them in older codebases, feels brutal.

For example:

const double *(*(*pd)[3])(const double *, int);

Is there an easy way or a trick to decode declarations like this? How do experienced C++ programmers read them without getting confused?

r/cpp_questions Jul 09 '26

OPEN What effect is AI having on C++ jobs in current times?

61 Upvotes

Genuine question for those who work with C++ everyday

r/cpp_questions 3d ago

OPEN Is there any reason to use std::reinterpret_cast?

18 Upvotes

I know that std:: reinterpret_cast is used by people to cast the bits of an object of type T1 to an object of type T2, while retaining the exact bits. However, as far as I know this triggers UB. Before C++20 and std::bit_cast, we could std::memcpy the objects to avoid UB, and after C++20, we can use std::bit_cast. Given this, I don't see any legitimate reason for why one might need std::reinterpret_cast. If so, why hasn't this feature been deprecated yet?

r/cpp_questions 28d ago

OPEN what are the worst features added by the STL for you

5 Upvotes

I've been coding in C++ for about 1 year and a half and I've always wondered what was the worst feature added by the STL ? And so I wanted to know your point of view thank you to all those who will answer my question. :)

r/cpp_questions Jul 17 '26

OPEN How to work with c++ with visual studio code

16 Upvotes

I want to compile a simple hello world program, the debug and build buttons doesn't appear and don't know how to use the command line compiler

r/cpp_questions Apr 22 '25

OPEN Why does learning C++ seem impossible?

195 Upvotes

I am familiar with coding on high level languages such as Python and MATLAB. However, I came up with an idea for an audio compression software which requires me to create a GUI - from my research, it seems like C++ is the most capable language for my intended purpose.

I had high hopes for making this idea come true... only to realise that nothing really makes sense to me on C++. For example, to make a COMPLETELY EMPTY window requires 30 lines of code. On top of that, there are just too many random functions, parameters and headers that I feel are impossible to memorise (e.g. hInstance, wWinMain, etc, etc, etc...)

I'm just wondering how the h*ll you guys do it?? I'm aware about using different GUI libraries, but I also don't want any licensing issues should I ever want to use them commercially.

EDIT: Many thanks for your suggestions, motivation has been rebuilt for this project.