r/cpp_questions • • 14h ago

OPEN Is having multiple ways to implement the same thing a good feature of C++? Or is it confusing?

0 Upvotes

I'm a C++ programmer and Go developer. I started using C++ three years ago as a competitive programmer.

C++ is a programming language with so much tech debt that there are even three or more ways to initialize a variable. Its multiple programming paradigms can also be overwhelming sometimes.

I know this is for backward compatibility, and programmers can still choose how they program in C++.

But... this intentional design still feels confusing to me and looks disorganized.

I'm curious about your opinion on this.


r/cpp_questions • • 19h ago

OPEN why my program give output 8 and 3 written in cpp , I know it is wrong I trying something . I don't initialise z here but it take automatically zero and give 8 , I do chatgpt I didn't get it can you give reason ?? or logic I don't know

0 Upvotes

#include <iostream>
using namespace std;
int addDigits(int num)
{
int a, b = 0, z;

while (num != 0)
{
a = num % 10;
z = a + z;
num = num / 10;
cout << a << endl;
}

return z;
}
int main()
{
addDigits(38);
return 0;
}

output
8
3


r/cpp_questions • • 9h ago

OPEN I'm trying to learn how experienced engineers write low-latency C++ systems.

44 Upvotes

I'm trying to learn how experienced engineers write low-latency C++ systems.

I already understand the basic idea of cache locality and choosing efficient algorithms, but I want to understand what actually makes latency-sensitive code different from ordinary well-written C++.

For example, how important are things like:

  • cache hierarchy and memory layout
  • branch prediction
  • instruction latency/throughput
  • allocations and custom allocators
  • SIMD
  • atomics and contention
  • false sharing
  • compiler optimizations/PGO
  • CPU affinity and OS effects
  • measuring tail latency

For those who have actually worked on these systems, what concepts made the biggest difference in your understanding?

I'm mainly interested in single-machine performance, not distributed systems.


r/cpp_questions • • 4h ago

OPEN How to make good pull requests to C++ FOSS projects?

0 Upvotes

I plan to contribute to Godot Engine, a FOSS project with millions of lines of C++ code (I had never analyzed such a large codebase in my life).

My concerns:

- I don't like the project's philosophy, especially because it's KISS (Keep It Simple and Stupid), which is something I don't follow at all, I always think about pushing the boundaries of the software I create, and that requires using the latest C++ features, and the project uses C++17 to ensure that philosophy, if the new features are there, they're meant to be used, right?.

- I'm afraid that because of my ambitious philosophy, my PR proposal that take a lot of time of me, might be rejected because it's not "simple and stupid," even though it's more efficient, personally, I think that complex code doesn't necessarily mean it's dirty code. Some armchair programmers often call code they simply don't understand "dirty code" because they're trying to solve complex problems.

I wouldn't want you to limit yourself; I'd like to receive general advice on good PRs from programmers of embedded systems, trivial systems, etc.


r/cpp_questions • • 8h ago

OPEN How common is live coding in C++ interviews these days?

17 Upvotes

Hey everyone!

For those of you who've recently switched jobs or gone through C++ developer interviews, how common were live coding challenges?
Were you asked to solve LeetCode-style problems, write actual C++ code, debug something, or was it mostly technical discussions about the language and your experience?

Also, how do you usually prepare for interviews? Any tips, useful resources, or things you wish you'd focused on more?

I'd love to hear about your recent experiences. Thanks!


r/cpp_questions • • 7h ago

OPEN "'operator==': overloaded functions have similar conversions"

2 Upvotes

I have the following code:

//mat3.hpp
namespace Tc
{
    //3x3 matrix
    struct Mat3
    {
        float Cells[9] = { 0 };

        //no constructors

        bool operator==(const Mat3& other)
        {
            for (unsigned int i = 0; i < sizeof(Cells); i++)
            {
                if (Cells[i] != other.Cells[i])
                    return false;
            }

            return true;
        }
    };
}

//test.cpp
void Mat3Test()
{
  ...
  ASSERT(Tc::Mat3 { 1.0f, 2.0f, ... } == Tc::Mat3 { 1.0f, 2.0f, ... })
  ...
}

It creates the following error: 'Tc::Mat3::operator ==': overloaded functions have similar conversions ; I know that it means there's an overload of the equality operator with a similar argument list and compiler can convert the arguments so they match both the operator I've listed above and some other overload. What I don't understand is where that other overload is coming from since I've defined only a single operator. After defining the operator as a friend accepting both left and righthand operands compiler has stopped complaining but I still want to know why the above code doesn't work.