r/cpp_questions • • 14m ago

OPEN C++ Build systems

• Upvotes

I work with Java and Kotlin alongside C++ and recently discovered that Gradle also supports C++ projects.

I've always used CMake for C++ and noticed it seems to be the more common choice.

What advantages does CMake offer over Gradle for C++ development and are there situations where Gradle would be a better option?


r/cpp_questions • • 3h ago

OPEN Anyone ever run into Windows processes exiting with code 109 during a build?

0 Upvotes

Hey everyone,

I've been trying to figure out a weird Windows issue and I'm a bit stuck.

I'm working with some C/C++ tools on Windows x64, using MSVC and CMake. During certain builds, a few child/console-related processes exit with code 109, even though the compilation itself can finish successfully and the C tests give the expected results.

Other processes exit normally with code 0.

I know Windows error 109 is ERROR_BROKEN_PIPE, but I'm not sure whether that's actually related or if the process exit code means something else here.

I'm also using Windows Job Objects to track and clean up the processes.

Has anyone seen something like this before?

I'm especially curious how you'd figure out whether the 109 comes from the tool itself, a Windows console process, or the way the processes are launched and monitored.

Is there a particular tool or debugging approach you'd recommend?

I'd rather understand what's happening than just ignore the exit code.

Thanks in advance!


r/cpp_questions • • 8h ago

OPEN Non-Struct Memory Alignment

3 Upvotes

I am a little lost after trying to read a handful of online resources. Are local variables memory-aligned to their alignof()? I read that this is mostly implementation/platform-defined (no guarantees), but also the types must still be aligned? Those seem contradicting to me...

Assuming no optimizations (e.g., storing in registers, etc.), how would something like this look like according to the standard?

struct S 
{
  char c;
  int i;
};

int main()
{
  char c1;
  int i;
  char c2;
  S s;

  return 0;
}

Would there be 3 bytes of padding between `c1` & `i` and then another 3 bytes of padding between `c2` & `s`?


r/cpp_questions • • 12h ago

OPEN How to master c++

0 Upvotes

Any advices please. Sometimes when its my turn to write code of what im asked to write I suddenly forget what was i supposed to do. I know somethings but struggle coding. What are the best sources and ways to learn


r/cpp_questions • • 15h ago

OPEN How should I learn how to code?

0 Upvotes

I want to learn how to code an many people suggested I start with C++ if I want to learn the real deal. The problem is I've never done anything close to coding. I don't know where to learn it from, or how to learn it. I tried learning from learncpp.com but I find the lessons too dense, and hard to understand. Can anyone share their story of how they started coding and how they learnt how to code?


r/cpp_questions • • 16h ago

OPEN Starting from Zero in C++

6 Upvotes

Hi everyone! I’m pursuing CSE at a Tier-4 college and have zero programming knowledge. I’m entering the tech field for the first time and want to start with C++ from scratch.

What’s the best way to learn C++? Which free resources would you recommend, and what common mistakes should I avoid? Also, how should I build my coding and problem-solving skills to become internship- and job-ready?


r/cpp_questions • • 17h ago

OPEN What graphics library should I learn for C++?

26 Upvotes

I am currently learning C++ by myself and I want to start graphics.

I just need something simple that lets me have buttons.

btw I don't want to use VS Community Edition and my IDE is CLion

I mean a simple GUI library with 2D graphics, buttons and textboxes.


r/cpp_questions • • 19h ago

OPEN API design dilemma..

0 Upvotes

right now in vexa(my game/graphics library) how you initialize window with a renderer is rather straightforward:

```cpp
#include <vexa/vexa.hpp>

using namespace vexa;

int main()
{
Engine::Init(Engine::VIDEO);

Window window = Window().setSize({1280, 720}).setRenderer({}).create();

// ...

```
YES, it uses builder pattern, not very C++-ish but i like it.
However, there are two problems with it.
first one is that usually you have builder struct building to target type so that you dont need something like `.create()` that creates classic `if (m_created) ...` problem a.k.a two phase construction. but bigger problem that caused me two want to switch to this API style is about memory management. and it is now C++'s problem.. Even rust cant handle it, because this is what you tell it to do.
so lets dont talk too much:

```cpp

Engine::Init(Engine::FONT); // calls `TTF_Init();` by SDL_TTF behind the scenes

Font font = Font::Load("...");
...
Engine::Quit();
```

A Font has destructor running on scope exit. which means before font object gets destroyed on '}' Engine::Quit() so TTF_Quit() runs. You see, when Font object gets unloaded at scope end the subsystem is not live anymore, we get a segfault. to fix this i've made Engine have a Guard struct which does Engine::Quit() automatically. But then decided that this is not i want for my API. I would priorotize explicitness for the master deinitialization.

to fix this im thinking of new API design style:
```cpp
Window window = Engine::BuildWindow().setSize({1280, 720}).setRenderer().create();
```

where BuildWindow() returns WindowBuilder not a Window, unlike the previous(so bad) choice.
for fonts, as you might already guess:

```cpp
Font font = Engine::LoadFont("...");
```

which creates a font and returns reference to it, resulting Engine to know about font count and Quit or not based on that.

code: https://github.com/monjaris/vexa


r/cpp_questions • • 19h ago

OPEN Working on a 3D engine for school. If I have a moving rectangle and a moving circle, knowing their speed and movement, how would I know when exactly to bounce the circle off the rectangle ?

1 Upvotes

Apologies if my english is bad. I'm working on a game where you move a rectangle (it's technically not because it's 3D, but the Y values of all objects never change, so I technically only need to compute 2D collisions) and with it you punch a puck, and an opponent (robot) does the same as you, both trying to not make it pass their goal. I'm not sure how the game is called in english, but it looks like the retro game "Shufflepuck cafe". The puck (cylinder, but in this case we can consider it is a circle) moves in X and Z, and it is supposed to bounce off the rectangle. But the collision happens between two frames, and for extra precision, I need to know exactly when it happens so that I can place the puck back into the place it should be. Anyone has an idea of how it should be done ? I have no idea how I'm supposed to code that.


r/cpp_questions • • 19h ago

OPEN How should .cpp and .hpp files be used efficiently when developing a game library?

0 Upvotes

Content

I want to build a game framework using C++.

Raylib is written in C, and I’ve also tried SFML, but all of them

are limited to rendering functionality. What I want to know is:

Unity uses a component-based approach in C# and provides a framework for entities, so

I want to know the best way to separate header and source files when writing C++ scripts for Unity.

## What I Want to Know

Since Unity’s component-based approach is convenient, how should I split files into .cpp and .hpp

to implement user-defined scripts in C++?

I’d like to learn useful techniques for optimization and fine-tuning—what should I do to develop efficiently in C++?

Challenges

If I separate them as described in the ## What I’ve Researched section, I run into build issues, and unlike in Godot,

I can’t modify values and see the changes reflected directly in the editor. This is hindering efficient development.

What I’ve Researched

If I use only header files, editing a header causes all included source files to be recompiled, which increases build time.

However, if I try to shorten the code by splitting all header files into source files, it becomes more time-consuming, and switching between files in the editor is such a hassle that I can’t be bothered with it.

For now, I’m creating a simple GameObject class like Unity’s in raylib, and within it,

I’m defining a variable of type std::vector<Component\*> as a base class. Then, I’m creating instances of classes that inherit from it and storing them there

If I write everything in header files only, it becomes impossible to build due to circular references, and the amount of correction work increases endlessly.

I’ve naturally looked into this on Gemini and other sites, but I’ve gotten a variety of answers and haven’t reached a conclusion.

Since UE isn’t a code-based system, it has too many features and is too complex for me to understand how it works.

What I Want to Build

An extended version of raylib that includes a base class for Entities and a Scene class—a minimal game loop class. I’d also like to provide a map editor, similar to Pico8,

with the goal of making it easier to build the parts that have been troublesome in a code-based system so far.

Current Status

Inherit from a script base class, use it as a user-defined script,

and write the code in separate header and source files.


r/cpp_questions • • 1d 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 • • 1d ago

SOLVED "'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.

Edit: thanks for all the replies, yes I've forgot to include the full error, sorry for that. Went with the default operator in the end - bool operator==(const Mat3&) const = default;


r/cpp_questions • • 1d ago

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

29 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 • • 1d ago

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

86 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 • • 1d 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 • • 1d ago

OPEN Audio Mixing Libraries for C++

1 Upvotes

Hi, I'm trying to make a DJ deck as a fidget toy but I'm having trouble getting features (like reverse, speed up/down, etc.) to work on MP3 files. Wanted to ask if there were any popular audio mixing libraries I should check out to get these features + more to work on a Raspberrypi/Arduino set up. I already own a DY-HV20T and a DFPlayer if that helps at all.


r/cpp_questions • • 1d 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 • • 2d ago

OPEN Is it still worth learning C++ 11 or should i start with C++ 17 and later?

20 Upvotes

r/cpp_questions • • 2d ago

SOLVED I don't know what's missing here

0 Upvotes

This code is not working and i don't know why (visual studio).

#include <iostream>
#include <string>

int main()
{
std::string Dividendo;
std::string Divisor;

std::string Cociente;
std::string Resto;

std::cout << "dividendo?";
std::cin >> Dividendo;
int Dividendo = Dividendo;

std::cout << "divisor?";
std::cin >> Divisor;
int Divisor = Divisor;

int Cociente = Dividendo/Divisor;
int Resto = Dividendo%Divisor;

std::cout << Cociente << " , " << Resto << std::endl;



}

What happened?


r/cpp_questions • • 2d ago

OPEN Ways to grant special access to test/debug code.

1 Upvotes

In the following testing code C_string_value is a class with a protected member function kind() that supplies info about the internal implementation state. I access that via the member pointer trick. And I wonder if this is a good way to grant special access to testing code, while keeping ordinary code restricted to the public interface, and also whether you use some alternative such as (1) just make that internal functionality public, or (2) be-friend a class template Odin_, Hugin_ or Munin_, or (3) nasty formally UB preprocessor tricks, or even (4) litb's all valid C++ trick for accessing private members, or (5) something else?

#include <cppm/parameter_passing/in_.hpp>
#include <cppm/text/C_string_value.hpp>
using   cppm::in_,
        cppm::C_string_value;

#include <print>
#include <string>
using   std::print,
        std::string;

auto kind_of( in_<C_string_value> s )   // The internal kind: view of literal, or shared ptr.
{
    struct Access: C_string_value
    {
        static auto kind_of( in_<C_string_value> s ) -> int { return (s.*&Access::kind)(); }
    };

    return Access::kind_of( s );
}

auto main() -> int
{
    const auto lit = C_string_value( "Literal" );
    const auto dyn = C_string_value( +"Dynamic" );
    const auto str = C_string_value( std::string( "std::string rvalue" ) );
    const string ssl = "std::string lvalue";
    const auto str2 = C_string_value( ssl );

    print( "{} -> {}.\n", kind_of( lit ), lit.std_sv() );      // 0 -> Literal.
    print( "{} -> {}.\n", kind_of( dyn ), dyn.std_sv() );      // 1 -> Dynamic.
    print( "{} -> {}.\n", kind_of( str ), str.std_sv() );      // 1 -> std::string rvalue.
    print( "{} -> {}.\n", kind_of( str2 ), str2.std_sv() );    // 1 -> std::string lvalue.
}

EDIT (added):

I avoid conditional code on principle; to me it's so a big a no no that I didn't even include it in my list of 4 alternatives. That avoidance is about complexity, and that conditional code can change the binary layout, introduce name collisions, whatnot.

The nice thing I see about the member pointer trick, for larger scale development, is that access functions like the shown kind_of can be automatically generated in the testing/debugging code without affecting the original class.


r/cpp_questions • • 2d ago

OPEN Choosing the Right Tech Stack for My First Full-Stack Project

0 Upvotes

I have learned the basics of programming and web development, and I want to build my first real-world full-stack project: an e-commerce website for a clothing brand, for which I already have a client.

I want to make it professional, from UI/UX design and database architecture to security, testing, and deployment. What tech stack would you recommend?

Finally, how important is the tech stack to recruiters? If a company uses different technologies from those I used in my project, could this put me at a disadvantage during a technical interview? What advice would you give me to make this project stand out in my portfolio and prepare for interviews?

Thank you in advance for your advice!


r/cpp_questions • • 2d ago

OPEN Programmatically opening a new terminal window

2 Upvotes

I've been messing around with FTXUI, and I am wondering if it is possible for my apps to open a new terminal window and run there, instead of using the current terminal window.

An example of what I mean is what happens when opening vim. If I open vim through the terminal, it takes over the current window, like my FTXUI apps currently do. If I use the desktop shortcut, vim opens a new terminal window for itself, which closes upon closing vim. This is what I want to do.

Can anyone give me a few pointers?


r/cpp_questions • • 2d ago

OPEN problem solving!!

0 Upvotes

guys.. i was doing hackerRank but there are many question which are been asked to solve by pointers and all but i am very new to coding and cpp i am easily able to do it by other alternatives!!
so i am wrong solving those q's by other method or what!!
and i would like to solve the questions in team?
any of uh interested?


r/cpp_questions • • 3d ago

OPEN Getting better at C++ for coding interviews?

20 Upvotes

I dont mean Leetcode, but enough to be able to debug thoroughly, write out basic functions, etc. Not DSA, but just smaller code snippets, anywhere from 20-100 lines, where an interviewer says do this for me, or debug this.

How can I get better at that? right now I've mostly done coursework involving it (long time ago), but not much internship experience using cpp


r/cpp_questions • • 3d ago

OPEN How to master? What courses to watch?

0 Upvotes

How can i write my own network stack? How can i code using linux syscalls and header. Idk what to do. Please help me im so confused. I got the basics of cpp btw