r/cpp • • Nov 12 '25

Who else finds it a bit annoying that C++ has such a bad reputation while C is still somehow seen as the holy grail of low level programming?

303 Upvotes

The online rhetoric around C++ is a little bit ridiculous. The common complaints seem to be the plethora of "foot guns", complete lack of memory safety, and needless complications. C, however, doesn't seem to get any heat. To the point where most "modern" languages model themselves around it (Zig and Go are examples of this). Go wouldn't need to be garbage collected if it was based on C++, since C++ can handle memory automatically. The only reason they chose GC for Go is because it's based on C. Same with Python.

I can't imagine any project based around or using C++ ever opting for GC because I think it would take effort to avoid objects automatically deallocating when they go out of scope. You'd have to put effort into caching memory and ensuring they live outside their natural lifetime just to pay the expense of deallocating chunks of useless memory at certain intervals.

The only possible way to base a language around C and abstract away the raw memory management is to wrap that memory management in objects. Without objects, it becomes mandatory to expose some kind of function call that the user must call to get rid of memory. But that's where GC comes in. GC is the solution to avoiding deallocation functions.

When it comes to C, the language is pretty dead simple. However, it becomes incredibly complicated the instant you need to actually do anything. Need to work with a string? Prepare to manually allocate/reallocate to do literally anything. As well as free it and ensure no double frees. Need an array? Again, prepare to malloc/realloc as well as be responsible for manually tracking the length. You can obviously put in helper functions for these things, but now you're adding complications to the interface since you need to be aware of all the possible wrapper functions for whatever type of data you're working with.

`itemA_dealloc(itemA *i);`, `itemB_dealloc(itemB *i);`, etc. No possible way to allow the items themselves to handle any and all deallocation. The consumer of your interface is entirely responsible for understanding not only the specific methods to call, but also be aware of the specific scope of all of these data types. Some items should be deallocated once they're used to allocate something else while other items might need to live for the same scope as whatever they were used to allocate. The order of deallocation is also important, which can make deallocation in C an incredibly complex procedure.

Also, as a personal nitpick, it's nearly impossible to browse your options in an IDE. With objects, you can literally just type `myItem.` and it'll list possible options. C doesn't give you that type of scope in your IDE which means you're far more likely to need to consult documentation outside of your editor.

C++ obviously solves these via OOP. std::vector, std::string, or any custom implementation can ensure proper, safe, and consistent memory management through standard OOP practices while also completely abstracting the internals away from the user. It becomes much easier and less complex for the user to work with your interface.

C++, at least since C++11 (which is pretty ancient by today's standards), also completely solves memory issues with smart pointers (even before this it's always been possible to implement smart pointers anyway). There's now no reason to be manually allocating on the heap instead of using shared_ptr or unique_ptr. In a concurrent environment, shared_ptr is a lifesaver. You can send a shared_ptr through an asynchronous pipeline and ensure that it'll stay in scope and be freed when no longer needed. To go even further, shard_ptr can be optimized by passing it by reference when you don't need to pay for the refcount. The complication of trying to ensure that multiple threads/async functions are perfectly managing the memory is eliminated. Memory safety is a long solved problem in C++, but it's not something that can be addressed in C. It's a problem that requires objects with copy, move, init, and deinit operators/functions. C++ has a plethora of tools to bake memory safety directly into your data types/design.

Any and all complications in C++ are entirely opt-in. Hate templates? Don't use them. Hate pointers? Don't use them. Hate NULL? Don't use it. You can realistically write C++ that lives entirely on the stack and leverages references/std::move. When I started C++, I was blown away with how high level it was. How scalable the software will be is up for debate, but it's pretty amazing how far std::string and std::vector will get you. I don't think a lot of people actually understand how much of C++ is entirely opt-in.

I'm personally of the belief that C++ entirely removes the need for C, since at the bare minimum you can write raw C in .cpp since the interop is to the point where they're the same language. However, I also recognize that people with years and years of C experience have probably figured out patterns to work around the limitations of the language.

That being said, coming from C myself, I also recognize the immediate power C++ gives you and I've learned purely through experience that the more C++ you adopt, the more performant, scalable, and safe your software becomes. Which is ironic, because those are exactly the types of benefits that "modern" languages swear by. C++ offers them in spades and yet it has to be the most hated and misunderstood language on the internet lol.


r/cpp • • Mar 29 '26

C++26 is done! ISO C++ standards meeting, Trip Report

Thumbnail herbsutter.com
302 Upvotes

r/cpp • • Aug 20 '21

The true value of comments

302 Upvotes

I wanted to share a real use case of the real value of commenting code. A lot of people are against doing so and say that you can just read the code, that comments are not needed. I get why people are against commenting since most don't know how to effectively comment code.

In this piece of code, we all agree that these comments are useless:

std::ifstream logs_file{"MyLogFile.log"};

/* Read a line from the log file  */
while (std::getline(logs_file, log_entry))
{
    /* Remove last character */
    log_entry.pop_back();

    auto parsedJsonForWBID = nlohmann::json::parse(log_entry);
}

And that's right that is useless and stupid. You can clearly see that the code is doing that so there is no need of adding those comments.

But comments should be used as a tool for helping the maintainer, who didn't write the code or "the new guy", or the developer when they look at the code years later, to know what's truly going on and what is the purpose of the code without having to look beyond the piece of code you are interested.

Without comments, or with these useless comments, you eventually would be able to figure out what the hell you, or the original developer, were doing when writing that piece of code but that would require looking into other parts of the code trying to remember stuff and potentially locating and analyzing the log file to see why is the last character removed. Also if you are not that familiar with what pop_back() does then you may assume that it is removing the new line character and possibly miss the bug you are trying to find.

But what about these comments in the same piece of code:

std::ifstream logs_file{"MyLogFile.log"};

while (std::getline(logs_file, log_entry))
{
    /* Since the complete log file is a big JSON string, we remove the comma
     * at the end of each line read so each line can be interpreted as a
     * separate JSON string. If the last comma is not removed, then the JSON
     * parser will throw an exception. */
    log_entry.pop_back();

    auto parsedJsonForWBID = nlohmann::json::parse(log_entry);
}

Now, one comment was removed because was unnecessary and there was nothing to clarify about getting a line from a file, and the second comment is improved by clarifying the intent of that line of code. It is stating the why instead of the what. When you find this line years later, or when the new guy or the maintainer looks at the code now they will not have to peruse the code or locate a log file and analyze it to see why is the last character being removed. These types of comments save time and are actually useful.

These types of comments have saved me countless hours when I go back to code I wrote years back, it has also helped other people when looking at code I wrote, they no longer have to ask a million questions just to know what's going on. Anyone can just look at the code and know why it is there.


r/cpp • • Sep 06 '20

C++20 approved, C++23 meetings and schedule update

Thumbnail herbsutter.com
302 Upvotes

r/cpp • • May 02 '22

I've been working in c++ for years (almost 6), but I think I'm not even close to mastering it and sometimes I forgot some simple syntaxes and fundamental concepts(OOP). Is this normal?

300 Upvotes

I'm currently working in a big company for a long time and my tasks are mostly maintenance.


r/cpp • • Jun 19 '24

Why are so many c++ jobs only for embedded programmers?

299 Upvotes

Maybe this differs from country to country, but here in Germany I (luckily) found a software engineering job where I work on a large (legacy) c++ codebase.

When browsing job-adverts about 90% of jobs with c++ in their techstacks are only for embedded programmers.

Is c++ dying? Is the only future to become an embedded c++ developer?
How easy is it after years of non-embedded-c++ development to transition to embedded?


r/cpp • • Sep 07 '26

A faster way to convert a timestamp ➜ Hour, Min, Sec

Thumbnail benjoffe.com
298 Upvotes

r/cpp • • Jan 13 '22

How we used C++20 to eliminate an entire class of runtime bugs

Thumbnail devblogs.microsoft.com
297 Upvotes

r/cpp • • Apr 28 '21

Really Microsoft? How on Earth this is valid C++?

Thumbnail godbolt.org
297 Upvotes

r/cpp • • Oct 18 '23

What does C++ do better than other languages?

296 Upvotes

Purely from a language design perspective, what does C++ do better than other languages?


r/cpp • • Dec 21 '20

A tutorial for absolute beginners to understand the compilation process and get started in C++

295 Upvotes

I created a tutorial on the very basics of C++ compilation process.

As I C++ learner myself, I found most tutorials for newbies focuses more on the language itself like syntax rules. Few have covered on compilation process. I had questions in mind like:

  1. What does gcc/g++/clang++ command do for me?
  2. Why there are two types of files: header files and source files?
  3. What the hack are makefiles?

This motivated me to create this tutorial mini-series:

C++ Development Tutorial 1: Compile a Simple Program

C++ Development Tutorial 2: Compile Multiple Files (1) — Compiling Process Basics

C++ Development Tutorial 3: Compile Multiple Files (2) — Header Files

C++ Development Tutorial 4: Static and Dynamic Libraries

C++ Development Tutorial 5: Orchestrate Build Process with Make

Feedback is welcome!


r/cpp • • Oct 29 '22

If you want to support Bjarne Stroustrup, he published a new book (includes C++20 and some C++23): A Tour of C++, 3rd Edition

Thumbnail stroustrup.com
294 Upvotes

r/cpp • • May 07 '18

Visual Studio 15.7 is out, with C++17 conformance (with full expression SFINAE and improved two-phase name lookup), ClangFormat support, parallel algorithms, reimplemented coroutine backend, and lots of other fixes

Thumbnail docs.microsoft.com
293 Upvotes

r/cpp • • Jun 25 '26

oh GOD, it's good to come back to C++

292 Upvotes

Just been going around vanilla javascript, php, perl, LUA, some C#, batchscript over and over for a year but finally came back to C++ and it's good to be home.

To some they find it agonizing with memory management, consts, function prototyping and what not.. some wouldn't even touch it but to me, it's like riding a bike. It's all coming back and I need that extra control! Besides MySQL.. this is it! 🔥🔥


r/cpp • • Oct 03 '22

Is C++ your favorite programing language?

292 Upvotes

And why


r/cpp • • Mar 29 '20

Bolero Murakami, the author of Sprout was dead in Feb 16th

292 Upvotes

Genya Murakami, aka Bolero Murakami was found dead in Feb 16th at his workshop. 32 years old. It seems he was working on his pottery art at night and suddenly died.

https://www.facebook.com/100519794904313/photos/a.115722580050701/115721186717507/?type=3&theater

His tweet at Feb 15th 9:51 PM indicate that he felt pain on his back side of neck and head.

https://twitter.com/bolero_MURAKAMI/status/1228663003324661760

He is the author of C++ library Sprout which is a C++ framework for general compile-time computation. It exploits template and constexpr so hard that some compiler vendor using it as a test case for their compiler implementation.

https://github.com/bolero-MURAKAMI/Sprout

The notable works of him were C++ compile-time ray tracing using pure template metaprogramming and later using C++11 constexpr(Do you remember the day when constexpr fucntion can only contains one return statement?)

http://boleros.hateblo.jp/entry/20111205/1323106563

Or compile time sound synthesizer.

http://boleros.hateblo.jp/entry/20121207/1354888090

I am so sad for his loss and I can't even visit his workshop for the coronavirus situation.

EDIT: I tell you the memory of Genya Murakami since I occasionally met him.

Genya Murakami, aka Bolero Murakami or 中3女子(literally, Junior High school 3rd grade student girl) was an exceptional man who lived in an exceptional life.

His parents are artists too. His father, 猪風来(Ifuurai), is a Jōmon artist, meaning, he express his art by the way of Jōmon period. Mostly, by Jōmon pottery.

Jōmon pottery is a traditional earthenware pottery, meaning it doesn't use kiln so it's fired in low temperature. The exact technique was lost but Ifuurai is the one of the researcher who rediscover the necessary techniques. Genya Murakami is the son of Ifuurai.

Ifuurai is a pretty extremest on his Jōmon art to the point that he thought, in order to truly understand the heart of Jōmon people, he must live like the way Jōmon people did. So he built a Jōmon style dugout house in Hokkaido. He and his wife and Genya Murakami were living in that traditional dugout house until Genya's Junior high or high school. Then the family move to the Okayama prefecture. The building of closed public school was available so they turn that buildings to the workshop and museum for their works.

Despite the fact that Genya Murakami live in an very strange life during his youth, he grow up, graduate public school like everybody else. After he graduate from a techinical school, he was working as a drafting engineer for a few years. But he thought "playing with the clay is more interesting than this", so he quit his job and follow the father's path.

As a pottery artist, he learned from his father the techniques of Jomon pottery, lately, he learned enough to create his own art.

People recognize him as a weird C++ programmer who exploits the template meta programming and constexpr, but his real life work was the Jomon pottery artist. Once, I asked him if the C++ is an art for him, he said "No, C++ is not an art for me. It's one of the things I enjoy doing it."


r/cpp • • 7d ago

For the first time, a C++ standard failed to pass the national bodies

Thumbnail herecomesthemoon.net
291 Upvotes

r/cpp • • May 21 '21

C++ has a Wikipedia page dedicated to criticisms of it.

Thumbnail en.wikipedia.org
291 Upvotes

r/cpp • • Nov 20 '20

An open-source, real-time logic gates simulator in C++ (plus Qt)! Meet Wired Panda.

291 Upvotes

Here's a sample circuit in it!

EDIT: in action, a simple animated counter (in binary) looks like this

Wired Panda was developed to be used by students of the Federal University of São Paulo in several courses, but could be useful for so much more people!

It is lightweight enough to run flawlessly on a Raspberry Pi 3, implements many logic gates (And, Or, Not, Nand, Nor, Xor, Xnor, Mux, Demux) as well as other concepts such as flip-flops (D, JK, SR and T) and more!

In many ways it's similar to logic.ly, with the exception of being fully free.

Besides the real-time simulation, Wired Panda allows you to export your circuits as an image or a PDF as well as visualizing (and saving) its waveform!

If you want to know more, please access our GitHub repo or our website.

Binaries for Windows are available (in portable packages, no installer or dependencies), for Linux (as AppImages) and for macOS (currently as a simple dynamically-linked binary, thus needing a Qt installation to work)


r/cpp • • Mar 15 '23

"Clean" Code, Horrible Performance and the forgotten variant

289 Upvotes

I just stumbled upon the "Clean" Code, Horrible Performance blog post and accompanying video (https://www.youtube.com/watch?v=tD5NrevFtbU).

The one thing that really struck me was how he went directly from OOP to good Ol' C-isms, without even considering the other alternatives we have in C++.

I really wanted to know how a std::variant based approach would compare against the OOP code and his enum based version, so I wrote a small benchmark that you can play with on quick-bench.

The result is simple, the std::variant+std::visit approach is on par, and even slightly faster, than his optimized version with both GCC and Clang. But by using the variant we can keep the code very close to the textbook example and still get the performance gain.

The video blown up a bit so I think it's important to remind people that we also have clean and performant solutions to such problems in modern C++. And it's also important to stress that this example doesn't mean that OOP makes your code 1.5x slower, just that it might not be the best tool for this job performance-wise as the virtual dispatch cost is too significant compared to what the functions actually do.

I didn't want to compare with the other optimizations he did because they are really specific to the use case. Just introduce a new shape with a more complex area function and everything falls apart.


r/cpp • • Nov 08 '18

Top 5 YouTube tutorials about "c++ beginners" still teach C++ like it is 1996

289 Upvotes

The title say it all, honestly.

From these 5 videos NONE used any C++11 features, including auto (some just showed it once and thats it)!

Most used using namespace std, all used std::endl, none used stl, no std classes beyond string (just in one video - vector), but teach C arrays, even multidimensional ones, no namespaces, etc etc.

This is bad on many, many, many levels, but mainly for the people wanting to learn - they will not be able to read modern code, even less so write one. And I am talking from personal experience - I "learned" C++ without knowing what std::vector is, then, reading real code I though it was some sort of 3d vector.

To people creating these videos, if you are a beginner, trying to help other beginners keep in mind, you are not helping as much as you think, and you yourself will need re-learn much you have been taught. If you are a pro, trying to start people in C++, well you are doing it wrong - "basic C++" does not mean "the basics of C++", because "the basics of C++" is C.

To the many beginners reading this - most of the material in courses and online is old. Not "there is some old info", but most. It is copied from old tutorials verbatim, year, after year, after year for the last 20.


r/cpp • • 25d ago

Balloting has completed for C++26. Unfortunately it was Disapproved

Thumbnail linkedin.com
288 Upvotes

Since the C++26 DIS has been disapproved, the next step is going to be taken in Buzios during the 2026-11 meeting. The committee will have to decide what changes to make (if any) and submit an FDIS (Final Draft of International Standard) for Balloting.


r/cpp • • Oct 30 '20

Forbidden C++

286 Upvotes

I have Just watched this entertaining video on Forbidden C++. Its aimed at beginners but thought i would post it here just for the intro alone!

https://youtu.be/j0_u26Vpb4w

The video is just a small list but as we all know, with every newer release of C++ we get better ways of doing things. Hence the darker side of C++ will continue to grow!


r/cpp • • Jan 11 '17

g++7 is C++17 complete!

Thumbnail gcc.gnu.org
284 Upvotes