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
Terminal resize issue with Ncurses
I am working on a small TUI app with c and ncurses library. In TUI apps, it is common to resize the terminal using ctrl+'+'
or ctrl+'-'
, so i am working in it's implementation.
i attached a handler for this purpose on SIGWINCH signal, this handler deletes windows and recreates them with the new dimensions. Because some windows have a specific decoration and some have specific sections to print text, i found it easier (and i think more efficient) to do it this way.
Increasing the size works as expected, but decreasing has really weird behavior. When the terminal gets resized to a smaller size than what it started with, the app crashes with "Core Dumped" error.
this is the error i am getting:
Fatal glibc error: malloc.c:2601 (sysmalloc): assertion failed: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0) Aborted (core dumped)
void handle_winch(int sig)
{
kill_panel();
refresh();
clear();
ncinit();
initui();
mkmenu(panel); // this function gets some data and prints it to panel->req_pad PAD.
}
void kill_panel()
{
delwin(panel->req_win);
delwin(panel->req_pad);
delwin(panel->det_win);
delwin(panel->main_win);
free(panel);
endwin();
}
void ncinit()
{
setlocale(LC_ALL, "");
initscr();
start_color();
noecho();
cbreak();
curs_set(FALSE);
keypad(stdscr, TRUE); // enable extea keys.
/* Some Color Initialization */
}
void initui()
{
panel = malloc(sizeof(Panel));
create_subwin(LRATIO, RRATIO); // this function initializes the UI (creates windows and PADs)
scroll_index = 0;
first_line = 0;
last_line = getmaxy(panel->req_win) - 1;
}
Recommended third-party libraries
What are the third-party libraries (general or with a specific purpose) that really simplified/improved/changed the code to your way of thinking?
https://redd.it/1j7eiqo
@r_cpp
C++ next steps
Alrighty,
So I decided to try and pick up c++. I just completed what I would call a survey course online. It gave a good overview of the big c++ pieces (pointers, references, classes, polymorphism) and I learned a lot. Each lesson and section ended with an exercise where you could test what you learned but it wasn't "connected" to anything, it was just proof of concept.
What id like now are courses or books or resources or something that can help me connect building little, simple programs that connect a front end interface of some kind to a back end. Just so I can build simple easy things to practice and get better. But I'm not sure where to turn.
If anyone has any suggestions, I'd really appreciate it.
https://redd.it/1j6z0uj
@r_cpp
Improving on std::count_if()'s auto-vectorization
https://nicula.xyz/2025/03/08/improving-stdcountif-vectorization.html
https://redd.it/1j6nsfm
@r_cpp
Bjarne Stroustrup on How He Sees C++ Evolving
https://thenewstack.io/bjarne-stroustrup-on-how-he-sees-c-evolving/
https://redd.it/1j5tgx4
@r_cpp
Question: why are you for/against linalg in the std?
Please let me know.
My take: the blas/lapack system is The standard, and it works. It's known. You can't do any of this stuff naively with acceptable performance.
Everyone and their grandmother knows you write your own stuff if you know the exact size or exact geometry of the problem. Most won't have to.
We already have the weird execution flags that can be used to overloaded, and C++ has types. It would be fantastic for overloads that don't exist today but everyone has written themselves anyways (like real eigenvalues).
So why are you against making the worldwide standard for linalg part of the C++ standard? Any clear arguments for I've missed it you wish to fix?
Thank you all and have a nice weekend!
https://redd.it/1j5tr6b
@r_cpp
The Old New Thing: How can I choose a different C++ constructor at runtime?
https://devblogs.microsoft.com/oldnewthing/20250306-00/?p=110942
https://redd.it/1j5hsev
@r_cpp
Should I use parameters of global variables?
I am working on an assignment for my c++ class and am wondering how to approach this problem. We are supposed to display a game summary with many different outputs. If I were to create this many parameters the code would be longer and messier. I am wanting to put global variables instead, but my professor said it is really bad and to never do it. what are your thoughts? -
void displayGameSummary() {
cout << "=== Game Summary ===" << endl;
cout << "Total Rounds Played: " << endl;
cout << "Total Wins (Regular): " << endl;
cout << "Total Wins (Blackjack): " << endl;
cout << "Total Losses (Regular): " << endl;
cout << "Total Losses (Blackjack): " << endl;
cout << "Total Ties (Regular): " << endl;
cout << "Total Ties (Blackjack): " << endl;
cout << "Final Balance: " << endl;
cout << "Net Gain/Loss: " << endl;
cout << endl;
cout << "Thank you for playing CodeJack: The Blackjack Simulator!" << endl;
cout << "We hope to see you again soon.";
}
https://redd.it/1j59p9f
@r_cpp
Lotus programming language
Me and my friend have been working on a programming language called Lotus, built with C++. Recently we have made the 1.0 version. We started it just for to get some experience, but now we are thinking that it actually might be useful to people. In future, we're aiming to make memory management easier, and I personally want to make GUI development simple. And we also have VS Code extension. The language is still in development, and we would love to hear some feedback
Repo: https://github.com/ScrumboardCompany/Lotus
https://redd.it/1j52zsx
@r_cpp
Expression Templates in C++
https://rifkin.dev/blog/expression-templates
https://redd.it/1j4wio5
@r_cpp
std::array in C++ is faster than array in C. Sometimes
https://pvs-studio.com/en/blog/posts/cpp/1231/
https://redd.it/1j4w8tq
@r_cpp
MSVC C++20 compiler bug with modules and non-exported classes
Full repro is available as a git repository here: https://github.com/abuehl/mod\_test
If two non-exported classes from different C++ module interface units have the same name, the compiler uses the wrong class definition and for example calls the wrong destructor on an object.
Reported here: https://developercommunity.visualstudio.com/t/post/10863347 (Upvotes appreciated)
Found while converting our product to using C++20 modules.
https://redd.it/1j4uepj
@r_cpp
Sourcetrail 2025.3.3 released
Hi everybody,
Sourcetrail 2025.3.3, a C++/Java source explorer, has been released with small updates to the Java Indexer, namely:
Add support for Eclipse JDT 3.40 (Java 23)
Update Gradle support to 8.12
Unfortunately, I can't post an announcement for this release in the Java subreddit, but maybe for some C++/Java developer here, this is also of interest.
https://redd.it/1j4swyb
@r_cpp
Game development C++
Im making a dungeon escape game and im confused
Should i do
Allegro
Or SFML
Or what other
Also in Visual Studio 2022
It ask for me what to download
Which do i click
Desktop development with c++
Mobile development with c++
Gane development with c++
Pls help lol
First time game maker
https://redd.it/1j4rczb
@r_cpp
Another Tool for Checking Library Level API and ABI Compatibility
Hi Everyone,
A few years ago I created a tool that can detect library level API and ABI compatibility breaking changes based on source code, as my thesis project. Recently, I decided to make it public, so that it might come in handy to some people.
If you're interested, you can find it at github.com/isuckatcs/abicorn-on-graduation-ceremony
https://redd.it/1j4hb61
@r_cpp
Memory Pool with Pointer to Pointer – Is This a Good Approach?
Hi everyone,
I've been working on a **memory pool implementation in C++**, where I allocate memory blocks and manage fragmentation. Instead of returning raw pointers, I store **pointers to pointers** (`char**`) to allow defragmentation without invalidating existing references. However, I'm unsure if this is a good approach or if I'm introducing unnecessary complexity.
# My Approach
* Memory blocks are allocated inside a pre-allocated pool.
* Each allocation returns a `char**`, which holds a pointer to the allocated memory.
* When defragmenting, I update the `char*` inside the `char**`, so existing references stay valid.
* Freed memory is added to a **free list**, and I attempt to reuse it when possible.
* The system includes a **defragmentation function** that moves blocks to reduce fragmentation.
# My Concerns
1. **Is using** `char**` **a good idea here?**
* It allows defragmentation without invalidating pointers.
* But, it might introduce unnecessary indirection.
2. **Memory leaks and dangling pointers?**
* The `free()` function erases blocks and adds them to the free list.
* After defragmentation, are there potential issues I haven't considered?
3. **Performance trade-offs**
* Sorting and shifting memory might be expensive.
* Is there a better way to manage fragmentation?
# Code
[main.cpp](https://pastecode.io/s/grcrhj51)
[log from console](https://pastecode.io/s/ynq5cdko)
https://redd.it/1j7gc7p
@r_cpp
Doubt how to start
Hi guys, I'm trying to start learning c++, I heard about this site called learncpp.com, is it good enough or there should be some other way I should learn? Thanks is advance for ur suggestions
https://redd.it/1j751gz
@r_cpp
Resource for Learning Clang Libraries — Lecture Slides and Code Examples (Version 0.3.0)
https://discourse.llvm.org/t/learning-resource-lecture-slides-for-the-clang-libraries-edition-0-3-0/85057
https://redd.it/1j6qw3q
@r_cpp
comboBoxSearch: A Single-header Library to Easily Create a Search Suggestions System for Win32 comboBoxes
https://github.com/brightgao1/comboBoxSearch
https://redd.it/1j62kv8
@r_cpp
Cpp devs at Big Tech: what kind of work do you do & how did you get there?
Hey, I'm curious about different roles that use C++ at Big tech companies and how people align themselves with those roles. I've seen quite a bit of them be niche so I was wondering how people entered those domains and problem spaces (Kernel dev, AR/VR, media, DBMS, etc).
Would love any resources or pathways that led you to where you are. Thanks!
https://redd.it/1j5ulh9
@r_cpp
Clang 20 Changelog.
https://releases.llvm.org/20.1.0/tools/clang/docs/ReleaseNotes.html
https://redd.it/1j5q3xz
@r_cpp
Seeking Tool for Auto Deployment of C++ and .NET Windows Application
Hi everyone,
I'm currently working on a project that involves both C++ and .NET Windows applications. I'm looking for a tool that supports automatic deployment for both types of applications. In the .NET world, we have ClickOnce, which is good for .NET applications, but I need something new tool that can handle both C++ and .NET.
Does anyone know of a tool or framework that can manage the auto deployment of both C++ and .NET applications? Any recommendations or insights would be greatly appreciated!
Thanks in advance!
https://redd.it/1j5eytj
@r_cpp
How much is the standard library/std namespace used in the real world?
Modern "best practice" for C++ seems to suggest using the standard library as extensively as possible, and I've tried to follow that, essentially prefixing everything that can be with std::
instead of using built in language features.
However when I look at real life projects they seem to use the standard library much less or not at all. In GCC's source code, there are very few uses of the standard library outside of its own implementation, almost none in the core compiler (or the C/C++ part)
And HotSpot doesn't use the standard library at all, explicitly banning the use of the std
namespace.
LLVM's codebase does use the standard library much more, so there are at least some major projects that use it, but obviously it's not that common. Also none of these projects actually use exceptions, and have much more limited use of "modern" features.
----
There's also the area of embedded programming. Technically my introduction to programming was in "C++" since it was with a C++ compiler, but was mostly only C (or the subset of C supported by the compiler) was taught, with the explanation given being that there was no C++ standard library support for the board in question.
Namespaces were discussed (I think that was the only C++ feature mentioned) where the std
namespace was mentioned as existing in many C++ implementations but couldn't be used here due to lack of support (with a demonstration showing that the compiler didn't recognise it). It was also said that in the embedded domain use of the std
namespace was disallowed for security concerns or concerns over memory allocation, regardless of whether it was available on the platform, so we shouldn't worry about not knowing about it. I haven't done any embedded programming in the real world, but based on what I've seen around the internet this seems to be generally true.
But this seems to contradict the recommended C++ programming style, with the standard library heavily intertwined. Also, wouldn't this affect the behaviour of the language itself?. For example brace initialization in the language has special treatment of std::initializer_list
(something that caught me out), but std::initializer_list
would not be available without use of the std
namespace, so how does excluding it not affect the semantics of the language itself?
So... do I have the wrong end of the stick here, so to speak? Should I actually be trusting the standard library (something that hasn't gone very well so far)? Lots of other people don't seem to. Everything I learn about C++ seems to be only partially true at best.
https://redd.it/1j50lqj
@r_cpp
Assigning dangling references#include <iostream>
#include <string>
const std::string& foo(const std::string& s)
{
return s;
}
int main()
{
const std::string& s{ foo("getHello") };
std::cout << s;
return 0;
}
i in this example i think the output should be undefined behaviour since "getHello" a c style string needs to be explicitly converted to an std::string reference which will create a temporary object and function parameter s of foo will be referencing to that temporary string which will be destructed when foo returns its reference to string reference s. However the output is "getHello" i dont know why?
https://redd.it/1j51fic
@r_cpp
Announcing Guidelines Support Library v4.2.0
https://devblogs.microsoft.com/cppblog/announcing-guidelines-support-library-v4-2-0/
https://redd.it/1j4xzay
@r_cpp
Is it OK to move unique_ptr's between different program modules? (DLL's and EXE's)
I'm developing an application framework where functionality can be extended via DLL modules. Part of framework tooling includes an ability to edit "Resources" defined within each module via "Properties". So I have property and resource interfaces defined by the framework that look like this (in "Framework.exe"):
`class IProperty {`
`public:`
`virtual handleInput(Event& event) = 0;`
`};`
`class IResource {`
`public:`
`virtual std::vector<std::unique_ptr<IProperty>> getProperties() = 0;`
`};`
So a simple resource implementing this interface within a module might look like this (in "MyModule.dll"):
`class Colour : public IResource {`
`public:`
`std::vector<std::unique_ptr<IProperty>> getProperties() override {`
`std::vector<std::unique_ptr<IProperty>> mProperties;`
`mProperties.emplace_back(std::make_unique<PropertyFloat>("Red", &cRed));`
`mProperties.emplace_back(std::make_unique<PropertyFloat>("Green", &cGreen));`
`mProperties.emplace_back(std::make_unique<PropertyFloat>("Blue", &cBlue));`
`return mProperties;`
`}`
`private:`
`float cRed;`
`float cGreen;`
`float cBlue;`
`};`
Now let's say we have functionality in the framework tooling to edit a resource via it's properties, we can do something like this (in "Framework.exe"):
`void editResource(IResource& resource) {`
`std::vector<std::unique_ptr<IProperty>> mProperties = resource.getProperties();`
`// Call some functions to edit the obtained properties as desired.`
`// ...`
`// Property editing is finished. All the properties are destroyed when the vector of unique_ptr's goes out of scope.`
`}`
I've implemented it this way with the aim of following RAII design pattern, and everything seems to be working as expected, but I'm concerned that the properties are constructed in "MyModule.dll", but then destructed in "Framework.exe", and I'm not sure if this is OK, since my understanding is that memory should be freed by the same module in which it was allocated.
Am I right to be concerned about this?
Is this technically undefined behaviour?
Do I need to adjust my design to make it correct?
https://redd.it/1j4vie9
@r_cpp
Getting ready for modules: porting one of my projects. Discussing file naming, strategies for module naming and more.
Hello everyone,
I have decided to start porting one of my projects to C++ modules making use of the latest big three compilers, sticking to preview GCC15 for Linux.
The plan is to port libraries, one at a time, from a static library with headers to a CMI with whatever I need I am guessing.
And I have some questions/discussion.
# File naming conventions (extension)
There are four kinds of module units: module interface units, module implementation units, module partition interface units and module partition implementation units.
What should I use and why? I plan to settle with .cppm
for interface modules .cppmi
for module implementation, .cppmp
for module partition interface unit and .cppmpi
for module partition implementation, if I need all those.
Any other schemes I should try or avoid like the plague?
# File naming conventions (namespaces and module names)
Should I establish a correspondence between namespaces and folders?
Currently I have a two-levels namespace, a bunch of "modules" (in the sense of library + headers per "module"), called TopProjectns::Module
with corresponding src/TopProjectns/Module
folder for both cpp and hpp files.
Maybe creating a folder (this will be an incremental non-intrusive port that does not touch the current structure, in parallel) like modules-src/TopProjectns.Module
is a good idea?
# Build tools
I am currently using Meson. Unfortunately the module support is so so. Any hacks, recommendations for integrating module building, especially build order, in Meson?
I would like to not have to port the full build system.
# Compiler flags and module cache
A bit lost here, especially in the build order.
I expect to have to add flags by hand to some extent bc I want a unified file extension convention.
Any recommendations?
# Package consumption
I need to consume dependencies, mostly pkg-confog given via Conan.
# Consuming my project modules (before my static libraries) as modules for other modules
Not sure how this will be done currently. But I guess that object/library files + cmi interface are needed.
# Code completion
Does LSP work for modules partially or totally?
# IDE
Recognising file extensions as C++. I think this will be easy in Emacs it is just adding a couple of lines of Lisp...
Suggestions and previous experiences of what to do/avoid are very welcome.
https://redd.it/1j4t8t9
@r_cpp
gnuplot with C++
I'm trying to write a program in C++ using gnuplot, but I can't. I get the message " 'gnuplot' is not recognized as an internal or external command, operable program or batch file". Please help me fix this. Here is the code:
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
#define GNUPLOTNAME "gnuplot -persist"
struct Point
{
double x, y;
};
class Figure
{
int num;
Point *coord;
public:
Figure() {};
Figure(int num, Point _coord)
{
num = _num;
coord = new Point[num + 1];
for (int i = 0; i < num; i++)
coord[i] = _coord[i];
coord[num] = _coord[0];
}
~Figure()
{
num = 0;
delete[] coord;
coord = nullptr;
}
void save(string nameOfFile, int a)
{
ofstream file;
file.open(nameOfFile + ".txt");
{
for (int i = 0; i < num; i++)
{
if (coord[i].x == 0.0 && coord[i].y == 0.0)
file << "\n";
else
file << coord[i].x << " " << coord[i].y << endl;
}
if (a == 1)
file << coord[0].x << " " << coord[0].y << endl;
file.close();
}
}
void DrawLines(const string nameOfFile, int a)
{
string str;
if (a == 1)
str = "set grid\nset xrange[-5:15]\nset yrange[-2:10]\nplot \"" + nameOfFile + ".txt" + "\" lt 7 w lp\n";
if (a == 2)
str = "set grid\nset xrange[-5:15]\nset yrange[-2:10]\nplot \"" + nameOfFile + ".txt" + "\" lt 7 w p\n";
FILE pipe = popen(GNUPLOTNAME, "w");
if (pipe != NULL)
{
fprintf(pipe, "%s", str.cstr());
fflush(pipe);
pclose(pipe);
}
}
};
int main(void)
{
int l1 = 3, l2 = 3;
Point p1l1;
Point p2l2;
p10 = {1.0, 0.0};
p11 = {1.0, 6.0};
p12 = {8.0, 3.0};
// p13 = {6.0, 0.0};
p20 = {2.0, 1.0};
p21 = {2.0, 2.0};
p22 = {4.0, 4.0};
// p23 = {3.0, 1.0};
Figure z1(l1, p1);
z1.save("z1", 1);
z1.DrawLines("z1", 1);
Figure z2(l2, p2);
z2.save("z2", 1);
z2.DrawLines("z2", 1);
return 0;
}
https://redd.it/1j4rthn
@r_cpp
Looking for C++ formatter/linter combo like Prettier for Visual Studio
I'm fairly new to C++ development and using Visual Studio (not VSCode) as my IDE. Coming from a JavaScript background, I really miss the convenience of Prettier for auto-formatting and ESLint for catching issues.
Does anyone have recommendations for:
1. A good C++ formatter that can auto-format my code on save (similar to Prettier)
2. A reliable C++ linter that can catch common errors and style issues
3. Ideally something that integrates well with Visual Studio
I'm working on a small personal project and finding myself spending too much time on formatting and dealing with simple mistakes that a linter would catch.
Any suggestions from experienced C++ devs would be much appreciated!
https://redd.it/1j4ql0j
@r_cpp
Web sockets in c++
Can you recommend a library that helps you connect to ws in cpp?
Ive always used websocketpp but Ive seen that the last commit on github was about 5 years ago, are there any other good libraries I can use? Thanks
https://redd.it/1j45w3e
@r_cpp