-
Stay up-to-date with everything C++! Content directly fetched from the subreddit just for you. Join our group for discussions : @programminginc Powered by : @r_channels
I Built an MPI Cluster of VMs (LAN) to Render the Mandelbrot & Julia Sets—Ask Me Anything
I recently set up an MPI cluster on a network of Ubuntu virtual machines and used it to compute the Mandelbrot and Julia sets in C++.
https://github.com/joeybaderr/Parallel-Fractals
# What I Did
Configured a multi-node MPI setup with passwordless SSH, NFS-shared storage, and inter-node communication.
Parallelized Mandelbrot and Julia set computations in C++ to distribute pixel calculations across multiple worker nodes.
Each node processed a chunk of the image, sending results back to the master for final assembly.
# What I Learned
Setting up an MPI cluster isn’t as complicated as it seems—getting SSH and NFS right was half the challenge.
Dividing work row-wise vs. block-wise in an image can affect workload balancing.
Running things in parallel doesn’t always mean faster—communication overhead can be a major bottleneck.
Debugging MPI programs without proper logging or barriers is painful.
# Takeaways
Watching multiple machines collaborate to generate fractals was satisfying.
The output PPM images turned out well, even without focusing on performance.
I’m considering trying a GPU version next to compare results.
Please feel free to give me any pointers.
https://redd.it/1i785j2
@r_cpp
What’s your favorite feature introduced in C++20 or C++23, and how has it impacted your coding style?
https://redd.it/1i73ky9
@r_cpp
Type Inference in Rust and C++
https://herecomesthemoon.net/2025/01/type-inference-in-rust-and-cpp/
https://redd.it/1i6lpw5
@r_cpp
Conditional coroutines?
Currently this is not allowed in C++ specification, should it be?
template <bool V> auto foo() -> std::generator<int> {
if constexpr (V) {
coyield 1;
} else {
return anotherfnc();
}
}
>A function is a *coroutine* if its *function-body* encloses a *coroutine-return-statement* (\[stmt.return.coroutine\](https://eel.is/c++draft/stmt.return.coroutine)), an *await-expression* (\[expr.await\](https://eel.is/c++draft/expr.await)), or a *yield-expression* (\[expr.yield\](https://eel.is/c++draft/expr.yield)).
I personally find it surprising, intuitively I feel foo<false> shouldn't be a coroutine. Currently this is handled a bit differently by compilers:
|Compiler|Behaviour|
|:-|:-|
|Clang, EDG, MSVC|Error on definition of the template|
|GCC|Error when foo<false> (with return ) is instantiated. No error when foo<true> is instantiated.|
Side note: if you want to have foo<false> not be coroutine, you need to specialize:
template <bool V> auto foo() -> std::generator<int> {
coyield 1;
}
template<> auto foo<false>() -> std::generator<int> {
return anotherfnc();
}
Question: Do you consider this intuitive behavior? Or would you prefer foo to be coroutines only for foo<true> instantiation?
https://redd.it/1i6hjnq
@r_cpp
What's the differences between SetConsoleOutputCP with _setmode ?
Here's my little program that outputs Unicode characters to the console on Windows, it call `SetConsoleOutputCP(CP_UTF8)` to set the encoding of the console :
#include <locale.h>
#include <stdio.h>
#include <wchar.h>
#include <windows.h>
#include <io.h>
#include <fcntl.h>
int main(void)
{
// _setmode(_fileno(stdout), _O_U8TEXT);
SetConsoleOutputCP(CP_UTF8);
setlocale(LC_ALL, "en_US.utf8");
wchar_t* const str_ch = L"\r🍌金黃色的曙光\n";
wchar_t* const str_ja = L"\r🍌金色の暁\n";
wprintf(str_ch);
wprintf(str_ja);
}
It outputs
金黃色的曙光
金色の暁
The '🍌' disappeared.
If call `_setmode(_fileno(stdout), _O_U8TEXT)` instead, the output is correct
🍌金黃色的曙光
🍌金色の暁
I'm wondering what's the differences between SetConsoleOutputCP with \_setmode so that the outputs are different?
https://redd.it/1i6bxlm
@r_cpp
Easily Printing std::variant - C++ Weekly - Ep 464
https://youtu.be/-oSuITjrzgU
https://redd.it/1i63up9
@r_cpp
Faster rng
Hey yall,
I'm working on a c++ code (using g++) that's eventually meant to be run on a many-core node (although I'm currently working on the linear version). After profiling it, I discovered that the bigger part of the execution time is spent on a Gaussian rng, located at the core of the main loop so I'm trying to make that part faster.
Right now, it's implemented using std::mt19937 to generate a random number which is then fed to std::normal_distribution which gives the final Gaussian random number.
I tried different solutions like replacing mt19937 with minstd_rand (slower) or even implementing my own Gaussian rng with different algorithms like Karney, Marsaglia (WAY slower because right now they're unoptimized naive versions I guess).
Instead of wasting too much time on useless efforts, I wanted to know if there was an actual chance to obtain a faster implementation than std::normal_distribution ? I'm guessing it's optimized to death under the hood (vectorization etc), but isn't there a faster way to generate in the order of millions of Gaussian random numbers ?
Thanks
https://redd.it/1i610kj
@r_cpp
Is it worth learning C++ in 2025?
https://redd.it/1hysalq
@r_cpp
Banning threads for junior teams? Force multiprocess over multithread?
Hi all,
Had an interesting discussion today and would appreciate some advice.
Multithreaded code can be especially tricky for medium to junior level developers to write correctly. When a mistake is made, it can result in difficult to find bugs.
If the application you are working on needs to be very reliable (but isn't safety critical), what would you recommend for medium/low experience c++ teams?
Assume that the application will need to do 4 things at once and can't use state machines or coroutines. The various "threads" need to regularly exchange less than 10 KB of data a second.
Do you ban threads?
A few approaches come to mind:
1) train the team to know the dangers and let them use threads with best practices. More experienced (and paranoid/diligent) developers carefully audit.
Any suggestions for books/resources for this team?
2) and/or use a tool or technique to detect concurrency issues at compile time or during test? Thread sanitizer? cppcheck? ???
3) ban threads and force concurrency to be implemented with multiple processes. 4 processes each with 1 thread. The processes will communicate with some form of IPC.
Thanks for any advice!
https://redd.it/1hykfpe
@r_cpp
i look for a developer to create a domain checker
i want a developper to create for me an api or a script that check domain availability
it do that:
\-add suffix and prefix for a word by the user
\-check domains by the DNS message
\-having a fast speed ( for that i can do any approach sweet you like distributed systems or multithread)
https://redd.it/1hygjtu
@r_cpp
What is C++?
In this https://www.reddit.com/r/cpp/comments/1hy6q7u/c\_safety\_and\_security\_panel\_2024\_hosted\_by/ video and comments there is a consistent idea that some changes to the C++ language are not acceptable because they "are not C++". And I honestly don't know what the overall community thinks what C++ is. Hence I ask..
# What do you think C++ is?
https://redd.it/1hybnei
@r_cpp
I wanna make a little console game, but I'm using linux. What library should I use?
I wanna make a game inspired by javidx9?si=02dfcvsKhwnK-WC4">this guy, but I'm using linux (arch btw). Should I use any library, or there's an API like in windows?
https://redd.it/1hy62og
@r_cpp
Inside STL: Waiting for a std::atomic<std::shared_ptr<T>> to change, part 2
https://devblogs.microsoft.com/oldnewthing/20250109-00/?p=110738
https://redd.it/1hy0ofn
@r_cpp
MegaBoy - a Gameboy/Color emulator made in C++
Hello! I would like to share the project I've been working on for almost the last 10 months, which is a Gameboy emulator. It is my first big C++ and CMake project, and I've learned a lot doing it. I will appreciate if you check it out and star the repo! https://github.com/MeGaL0DoN/MegaBoy
https://redd.it/1hxtgnt
@r_cpp
How to fix it
Which is used for print in C++ a.exe or .a.exe
https://redd.it/1i74qf1
@r_cpp
Problems with includePath in VScode
I have installed qt with brew, program is working nicely, but i have some issues with VS code
#include <QApplication>
#include <QPushButton>
#include <QMessageBox>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QPushButton button("Click me!");
QObject::connect(&button, &QPushButton::clicked, [&]() {
QMessageBox::information(nullptr, "Message", "Button clicked!");
});
button.resize(200, 50);
button.show();
return app.exec();
}
\#include errors detected. Please update your includePath.
this is the error i'm getting
I have tried to change includePath in VS settings, but it just won't help
i tried this paths:
`/opt/homebrew/include/**`
`/opt/homebrew/Cellar/qt/6.7.3/include`
`/opt/homebrew/Cellar/qt/6.7.3/lib`
Guy from another community advised me to switch from intellisense to clangd
https://redd.it/1i6owr7
@r_cpp
How it felt to come back to C++ from Rust.
1. Lifetimes and Borrow Checker are just too good to be true. This probably goes without saying, and is the best reason to choose Rust.
2. The localisation of undefined behaviour with unsafe blocks and the separation of responsibilities makes the code very transparent. Even if there is a lot of unsafe code, not all of it is unsafe, so it is worth using Rust for that reason alone. Insecurity does not make the Lifetimes or Borrow Checker any less relevant.
3. I feel that Rust (or maybe any language that has an easy-to-use package manager) has a rather large number of small libraries. Of course, C++ has a much better standard library than Rust, and even more if you include Boost Libraries, etc.
4. After 5 years of Rust, I almost forgot how powerful C++ can be. C++20 had some surprises, so I built a tiny library to test the waters.It's a tiny C++ 20 library that provides a UDLs to make indent-adjusted multiline raw string literals at compile time. Check it out: https://github.com/loliGothicK/unindent.
https://redd.it/1i6jdjq
@r_cpp
Improving Code Safety in C++26: Managers and Dangling References
https://www.cppstories.com/2025/cpp26-safety-temp/
https://redd.it/1i6d2fs
@r_cpp
CPP Devs what you prefer?
VSCODE vs NVIM
What are the pro and cons ?
Vscode gives you 0 effort for setting things up while neovim require some level of setup.
One both are set up, what makes one superior/Powerful compared to other?
https://redd.it/1i66rk2
@r_cpp
The Beman Project: Bringing C++ Standard Libraries to the Next Level - CppCon 2024
https://youtu.be/f4JinCpcQOg?si=VyKp5fGfWCZY_T9o
https://redd.it/1i61mvh
@r_cpp
Exploring Parallelism and Concurrency Myths in C++
Recently, I read Debunking C++ Myths by Alexandru Bolboaca and Ferenc Lajos Deak, and one of the myths that stood out to me was: "There's no simple way to do parallelism and concurrency in C++."
It’s true that working with threads and synchronization in C++ used to be challenging, especially before C++11 introduced a standard threading library. But modern C++ has come a long way with features like std::thread, std::async, and the <future> library, which make concurrent programming more accessible. Libraries like TBB and parallel algorithms in C++17 (std::for_each, std::reduce) have also simplified things.
What’s your experience with parallelism and concurrency in C++? Have you found it as tricky as people say, or do modern tools and libraries make it manageable?
https://redd.it/1i5w7fd
@r_cpp
Handy Progress Tracking Script for Anyone Working through LearnCPP
I have been diving deep into C++ recently and going through all the content on learncpp.com before moving on to a couple other physical books I have on the shelf. I know there are plenty of other people who have mentioned using the site, so I thought I'd share this handy little progress report script. It's written in the dark language, and I know it doesn't have to do with interop, so mods, please remove if this is an issue.
The script just requires that you change the current lesson number string that you're on at the top, and then copy and paste it into the console on the table of contents page found on the homepage. It spits out your current lesson number, total lessons, and gives you a percentage completed. This kind of thing keeps me motivated when learning, so I figured I'd share.
const currentLesson = "7.7"
let numberRows = document.querySelectorAll(".lessontable-row-number");
let numbersArray = Array.from(numberRows);
for (let lessonNo in numbersArray) {
if (numbersArraylessonNo.innerText == currentLesson) {
console.log(You are on lesson number ${parseInt(lessonNo) + 1} out of ${numbersArray.length + 1}! That's ${Math.round((parseInt(lessonNo) + 1) / (numbersArray.length + 1) * 100)}% of the way done! Keep going!);
}
}
https://redd.it/1hyplob
@r_cpp
Looking for 3 people
Hello I just got into c++ for game development and i was wondering if there is 3 people who can help me learn!
https://redd.it/1hyl1jo
@r_cpp
Moving optional
https://devblogs.microsoft.com/oldnewthing/20241114-00/?p=110521
https://redd.it/1hyhlgf
@r_cpp
Does C++ allow creating "Schrödinger objects" with overlapping lifetimes?
Hi everyone,
I came across a strange situation while working with objects in C++, and I’m wondering if this behavior is actually valid according to the standard or if I’m misunderstanding something. Here’s the example:
```cpp
struct A {
char a;
};
int main(int argc, char* argv[]) {
char storage;
// Cast a `char*` into a type that can be stored in a `char`, valid according to the standard.
A* tmp = reinterpret_cast<A*>(&storage);
// Constructs an object `A` on `storage`. The lifetime of `tmp` begins here.
new (tmp) A{};
// Valid according to the standard. Here, `storage2` either points to `storage` or `tmp->a`
// (depending on the interpretation of the standard).
// Both share the same address and are of type `char`.
char* storage2 = reinterpret_cast<char*>(tmp);
// Valid according to the standard. Here, `tmp2` may point to `storage`, `tmp->a`, or `tmp` itself
// (depending on the interpretation of the standard).
A* tmp2 = reinterpret_cast<A*>(storage2);
new (tmp2) A{};
// If a new object is constructed on `storage`, the lifetime of `tmp` ends (it "dies").
// If the object is constructed on `tmp2->a`, then `tmp` remains alive.
// If the object is constructed on `tmp`, `tmp` is killed, then resurrected, and `tmp2` becomes the same object as `tmp`.
// Here, `tmp` exists in a superposition state: alive, dead, and resurrected.
}
```
This creates a situation where objects seem to exist in a "Schrödinger state": alive, dead, and resurrected at the same time, depending on how their lifetime and memory representation are interpreted.
---
(And for those wondering why this ambiguity is problematic: it's one of the many issues preventing two objects with exactly the same memory representation from coexisting.)
**A common case:**
It’s impossible, while respecting the C++ standard, to wrap a pointer to a C struct (returned by an API) in a C++ class with the exact same memory representation (cast c_struct* into cpp_class*).
Yet, from a memory perspective, this is the simplest form of aliasing and shouldn’t be an issue...
---
Does C++ actually allow this kind of ambiguous situation, or am I misinterpreting the standard? Is there an elegant way to work around this limitation without resorting to hacks that might break with specific compilers or optimizations?
Thanks in advance for your insights! 😊
https://redd.it/1hyf7s2
@r_cpp
The ergonomics of working with internal-only vcpkg libraries
# The goal
We have a monorepo, more by accident than by design. Something like:
Libs/
CMakeLists.txt # add_subdirectory(LibA) add_subdirectory(LibB)
LibA/
CMakeLists.txt
LibB/
CMakeLists.txt
Apps/
App1/
CMakeLists.txt # project(App1) add_subdirectory(../../Libs Libs)
App2/
CMakeLists.txt # project(App2) add_subdirectory(../../Libs Libs)
(There's no top-level `CMakeLists.txt` and each app builds its own tree of Libs.)
I'm converting to multiple repos by making everything (`LibA`, `LibB`, `App1`) a separately versioned vcpkg library in its own repo and making a port registry repo to match.
# The problem
For example, there's a bug in `App1`, because of `LibA`, which requires an interface change in `LibB` to properly fix.
In a monorepo, easy—make the change in all three, commit (optional: subtly break downstream dependencies because you don't version your libraries).
When they're all split across multiple versioned vcpkg libraries...
* How do I test the combined changes while developing? It seems like I want to somehow be able to switch from "from vcpkg registry @ version" to "from locally checked out library" or something.
* How do I uprev the three projects? Do I uprev `LibB` (and it's port), then change `LibA`'s dependency, then uprev `LibA` (and it's port), then change `App1`'s dependency, then uprev `App1`?
* Is it possible to make this process almost as easy as it was in the monorepo?
Just curious what everyone's experience is with this. Do you do something completely different for versioning internal libraries that you would recommend?
https://redd.it/1hy91en
@r_cpp
C++ Safety And Security Panel 2024 - Hosted by Michael Wong - CppCon 2024
CppCon
https://www.youtube.com/watch?v=uOv6uLN78ks
https://redd.it/1hy6q7u
@r_cpp
Questions regarding Ren Tech C++ phone interview
Have anyone had the experience of RenTech phone screen. It is said that it is going to be an 10-15 min interview. Had looked up on glassdoor. Mainly about linux version kernel and morden C++. Wondering if that is correct.
https://redd.it/1hxpu79
@r_cpp
SCM Puzzle Challenge
https://scmchallenge.com/
https://redd.it/1hxspyg
@r_cpp