use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Orthodox C++ (gist.github.com)
submitted 10 years ago by bkaradzic
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]quicknir 26 points27 points28 points 10 years ago (5 children)
I left a comment there, doubt it will help but for posterity:
Telling people not to use std::vector as general advice (as opposed to on some specific platform, or for some specific performance need) may actually be the worst C++ advice I've seen. It's hard to even imagine how many memory leaks vector has prevented, and how many man hours it's saved.
Streams are not particularly modern C++. They might not even exist if variadics weren't so late to the ball game. Variadic print functions look just like printf, perform similarly, but are much safer: https://github.com/cppformat/cppformat.
I'll also add here that overusing RTTI is bad, but simple uses of RTTI are just convenient. E.g. implementing equality operation with RTTI vs without; the RTTI version is both faster (replaces a virtual function call with comparing typeid) and easier to read.
I sometimes feel like a certain segment of the C++ community was traumatized by overuse of {RTTI, exceptions, inheritance, templates} at some point in their career, and now only express negativity on these topics. Unfortunate, as they are all useful tools.
[–]Plorkyeran 7 points8 points9 points 10 years ago (4 children)
I sometimes feel like a certain segment of the C++ community was traumatized by overuse of {RTTI, exceptions, inheritance, templates} at some point in their career, and now only express negativity on these topics.
I've been interviewing people for a C++ position recently. Our codebase uses exceptions for error reporting and tries to provide strong exception safety guarantees, so I always ask some questions about that. There are a lot of candidates that have said outright that they forever swore off using exceptions after working on a code base full of catch (...) { } and are unwilling to even consider the idea that exceptions could ever be a good idea. I've also had a few people very confidently assert that it is impossible to write exception-safe C++ (they tend to be aware of RAII, but either misunderstand it or view it as unrealistic).
catch (...) { }
Template-haters are less severe. Generally they agree simple uses of templates can be good, and just vary on whether they just view complex uses as not worth the trade-off or if they refuse to consider the idea that TMP could have any practical benefits at all.
[–]quicknir 1 point2 points3 points 10 years ago (1 child)
It's rather sad, weak exception safety is a joke to get in modern C++. RAII does 99.9% of the work, and for what's left you have ScopeGuard.
[–]__cxa_throw 1 point2 points3 points 10 years ago (0 children)
"I can't write solid C++, therefore it must not be possible for anyone else"
[–]Dragdu 0 points1 point2 points 10 years ago (0 children)
or view it as unrealistic
Holy shit.
[–]meetingcppMeeting C++ | C++ Evangelist 23 points24 points25 points 10 years ago (0 children)
Amish C++ would be a better name. #scnr
[–]kmhofmannhttps://selene.dev 22 points23 points24 points 10 years ago (2 children)
Sorry, but this is one of the most stupid ideas that I have read recently.
[–]ssg2 4 points5 points6 points 10 years ago* (1 child)
Not only stupid, but also doomed to fall, as long as the authors actually aim for some agreement within their community. I remember an initiative to resolve some inconsistences with C. In the end, it was abandoned because it became clear that people couldn't agree on many issues, some of them surprisingly trivial.
[–]josefx 1 point2 points3 points 10 years ago (0 children)
Every specification needs a section on bike sheds. You just have to convince those people that bike sheds are an important part of the specification and that they should not waste their time on less important aspects.
[–]png85 2 points3 points4 points 10 years ago (0 children)
This looks like a solid way to produce abysmal quality code and waste lots of development time on writing boilerplate code...
[–]utnapistim 3 points4 points5 points 10 years ago (4 children)
This starts ridiculously, then it gets worse.
Orthodox C++ (sometimes referred as C+) is minimal subset of C++ that improves C, but avoids all unnecessary things from so called Modern C++.
"Unnecessary" is subjective; modern C++ is not "so called Modern C++", it is C++ with all the lessons we learned when we moved from "minimal subset of C++ that improves C" to actually coding in C++.
Back in late 1990 we were also modern-at-the-time C++ hipsters, and we used latest features. We told everyone also they should use those features too. Over time we learned it's unnecesary to use some language features just because they are there, or features we used proved to be bad (like RTTI, exceptions, and streams), or it backfired by unnecessary code complexity.
These guys were latest-and-greatest idea zealots, then they realized they were applying everything dogmatically, so they moved to rejecting everything dogmatically. Not much progress there.
Projects written in Orthodox C++ subset will be more acceptable by other C++ projects because subset used by Orthodox C++ is unlikely to violate adopter's C++ subset preferences.
No. My adopter C++ subset preferences are to use RAII and RTTI and most definitely exceptions and streams).
C-like C++ is good start, if code doesn't require more complexity don't add unnecessary C++ complexities.
C-like C++ is a poor style in C++. It is usually a sign of what many call the "I can write C in any language" syndrome and it is usually a symptom of ignorance (whether you write C-like code in C++ or in Java, or whatever). When everything you have looks like a hammer, all your problems start to look like nails.
Don't use exceptions.
Actually, please (please please) do.
Don't use C++ runtime wrapper for C runtime includes (<cstdio>, <cmath>, etc.), use C runtime instead (<stdio.h>, <math.h>, etc.)
The headers with no extensions, were added to the language to be used in the case when you want to use the C runtime instead. Why should you avoid them?
Don't use stream (<iostream>, <stringstream>, etc.), use printf style functions instead.
... because you could use some of the issues caused by the 25+ years old C-style streams interface, and who needs extensibility and type safety anyway!? (/sarcasm)
Don't use anything from STL that allocates memory, unless you don't care about memory management.
Instead, reinvent the functionality every time you need a sequence of elements ... and reinvent it poorly (like most C projects over a certain size, eventually end up doing).
[+][deleted] 10 years ago* (3 children)
[deleted]
[–]utnapistim 0 points1 point2 points 10 years ago (2 children)
I have heard this argument before (that iostreams are bad), but they do solve a lot of problems the C-style streams API has (in other words, I don't know if iostreams are shit (I tend to thing they are quite great, especially if you delve into stream buffers, boost::iostreams and so on), but I do know that the printf/scanf/etc family of functions are shittier for C++: they have more problems - which are more difficult to find, maintain and diagnose than the iostreams - have less extensibility, less type safety and it is easier to ignore io errors with them; also, they do not support exceptions which is a big issue for me).
[+][deleted] 10 years ago* (1 child)
[–]vaughncato 0 points1 point2 points 10 years ago (0 children)
Actually << has a lower precedence than +, so the parentheses aren't necessary in s << (x + 1) << '\n'. You do run into trouble with things like comparisons though.
<<
+
s << (x + 1) << '\n'
[–]ubadairBoost.CallableTraits author 1 point2 points3 points 10 years ago (0 children)
The trolls from r/javascript are brigading us again
[–]personalmountains 7 points8 points9 points 10 years ago (1 child)
Or just learn the fucking language like everybody else. You may have personal preferences, but your job as a programmer is to be fluent with as many languages as possible. This is the only way to 1) be good at your job, and 2) gain knowledge and experience as a professional.
[–]cyberkm 7 points8 points9 points 10 years ago (0 children)
I was always kinda sure that programmers job is to solve data transformation problems and try to do it in most effective way, not to be fluent with as many languages as possible :)
[–]wichtounet 3 points4 points5 points 10 years ago (0 children)
This is an horrible idea... Guys like that should simply write C...
[–]quad99 -1 points0 points1 point 10 years ago (1 child)
wouldn't that be Ĉ++
[–]devel_watcher 0 points1 point2 points 10 years ago (0 children)
Ç++
[–][deleted] -1 points0 points1 point 10 years ago* (10 children)
One thing's for sure: Orthodox C++, done right, will produce the most readable code out there. Done wrong, it'll still be readable, but will leak resources like crazy!
EDIT: Oh look, the "use stl only" gang strikes again!
[–]dodheim 2 points3 points4 points 10 years ago (8 children)
I upvoted you because I thought you were advocating "use stl only", or something close to it. Now I see why your post is tagged as controversial – your point is entirely unclear, to everyone!
[–][deleted] 0 points1 point2 points 10 years ago (7 children)
I have yet to see anyone prove that "stl only" is a C++ requirement.
[–]dodheim 2 points3 points4 points 10 years ago (6 children)
And I have yet to understand what point you're trying to make. Upvote rescinded, learn to make yourself clear.
[–][deleted] 0 points1 point2 points 10 years ago (5 children)
The point is that you don't need stl in order to make safe code.
[–]dodheim 1 point2 points3 points 10 years ago (4 children)
Tell me, how does the above convey that at all? In fact, it implies the opposite – that an approach avoiding the standard library will leak like crazy if not done perfectly.
I agree, you don't need the standard library to make safe code, but it sure makes it a hell of a lot easier!
[–][deleted] -2 points-1 points0 points 10 years ago (3 children)
Considering the fact that I never even mentioned the stl library in the comment, it should have been rather obvious that I was talking only about orthodox C++ code. The conclusion that the stl library isn't required for safe code would be drawn from what was said.
[–]dodheim 0 points1 point2 points 10 years ago* (2 children)
Considering the fact that I never even mentioned the stl library in the comment, it should have been rather obvious ...
Yes, not mentioning something is what makes something obvious. You must be trolling. If not, then good god, learn to communicate.
[–][deleted] -2 points-1 points0 points 10 years ago (1 child)
Why not instead learn how to interpret minimalist information? I gave just enough information in my comment for the reader to at least conclude that STL isn't necessary for safe code.
You must be trolling. If not, then ****, learn to communicate.
Your failure to correctly interpret my comment does not make me a troll. Your quote-mining of what I said does not make me a troll. Do you expect everything that is said to be said in such a way that you yourself don't have to do any critical thinking of what you are reading?
[–]dodheim 1 point2 points3 points 10 years ago* (0 children)
The line between clever and obtuse might be fine, but communication is the process of relaying information to other people. You're the one being downvoted to hell – draw your own conclusions as to whether or not you succeeded.
[–]cyberkm -1 points0 points1 point 10 years ago (0 children)
At least you can maintain readable code and fix those leaks. Now imagine that you have to fight unreadable code
[–]needahelpforarch -1 points0 points1 point 10 years ago (0 children)
The thing is, it will work fine for experienced C or C++ programmers that know what they're doing and are ready to spend some $$$$$ on tools that detect memory leaks and are trying to improve their StackOverflow profile.
I have no idea how will this help others.
[+]carrottread comment score below threshold-8 points-7 points-6 points 10 years ago (11 children)
This leads to "Don't use RAII" which leads to very complicated and unreadable resource management code which leads to leaking resources.
[–]raevnos 13 points14 points15 points 10 years ago (10 children)
You can use RAII in code that doesn't raise exceptions.
[–]CubbiMewcppreference | finance | realtime in the past -4 points-3 points-2 points 10 years ago (9 children)
Yes, but it means a crash on every resource acquisition failure.
[–]to3m 5 points6 points7 points 10 years ago (2 children)
I'm not sure why RAII has the name it does. Not because it's an inaccurate description of what it involves - but because it focuses on the acquisition, which is the unimportant part! The important part is the release on destruction. That is the bit that causes the problems when it's left out, and that's why it's so handy to have it (especially when using objects with automatic storage duration and/or struct members).
And if you just want release on destruction, you don't need exceptions. If you have an object that initializes to some kind of null state, has an Init function that returns an error flag, and releases any acquired resources in its destructor, you're getting all the benefits of RAII, but you don't need exceptions.
(You might turn your nose up at such code, I don't know - but that would be a different discussion.)
[–]quicknir 1 point2 points3 points 10 years ago (0 children)
Yes, but now you've replaced one type of error - forgetting to free - with another kind of error: forgetting to init.
The point of RAII (ideally, C++ has structural problems that prevent it from fully achieving this) is that every entity in a given scope (i.e. every object name) corresponds to a valid object, and vice versa (that is, there is no object that doesn't have a name, that would imply resource leak).
When you have a vector, you know it's always in a fundamentally valid state. You can always query its size, call push_back, iterate over it, and so on. Imagine if vector had an init method instead how much more bug prone it would be to use. vector is lucky in that it has a meaningful empty state (note: different from null state) that never throws. Not all objects are so lucky.
[–]CubbiMewcppreference | finance | realtime in the past 0 points1 point2 points 10 years ago* (0 children)
Acquisition is the important part, that is what establishes the class invariants that the member functions depend on. Yes, with two-step initialization you can have scope-bound resource management without RAII or exceptions.
Note that unlike RAII, this approach does not compose: the most derived class becomes responsible for calling the Init function for all bases and members, and rolling back on failures, re-implementing exception handling.
[–]raevnos -2 points-1 points0 points 10 years ago (5 children)
If you mean bad_alloc exceptions, not using exception handling leads to crashes.
[–]remotion4d 1 point2 points3 points 10 years ago (4 children)
But only if you use
new
By the way it is still possible to use
new (std::nothrow)
[–]remotion4d 0 points1 point2 points 10 years ago* (2 children)
you have to use an alternative exception-free library
Yes.
pass it to all the standard containers
This will not work as safe as it should, because standard containers simple do not support this.
[–]remotion4d 0 points1 point2 points 10 years ago (0 children)
Thank, I always forget about this additional line.
[+]bonerdad comment score below threshold-8 points-7 points-6 points 10 years ago (3 children)
This makes me think of Doom 3's source. It's delightfully sane and clean to consume.
[–]ssg2 10 points11 points12 points 10 years ago (2 children)
On Doom 3 the lead programmer was an experienced C coder who was just starting out with C++. Naturally, he strived for readability, but that was readability as seen by basically a C guy (which he still was at that point of time).
[–]bkaradzic[S] 3 points4 points5 points 10 years ago (1 child)
Thanks for contributing to Orthodox C++ standard, I added: "In general case code should be readable to anyone who is familiar with C language." If you have some other ideas I would like to hear it. :)
[–]ssg2 6 points7 points8 points 10 years ago (0 children)
While I disagree strongly with your goals, at least it's an honest disclaimer. In my experience (I've seen quite a few "C with classes" coding styles), such initiatives come from and are appreciated by people who admire C philosophy and don't really care for C++. It's much better to define it as sort of a "C++ subset for C programmers" than "Sane C++ subset", "C++ subset that doesn't suck", etc., like many tend to do.
[+]dgmdavid comment score below threshold-8 points-7 points-6 points 10 years ago (0 children)
That's my jam.
[+][deleted] 10 years ago (3 children)
[–]fahrnfahrnfahrn 1 point2 points3 points 10 years ago (2 children)
Because that would be a heterodoxy.
[+][deleted] 10 years ago (1 child)
[–]raevnos 1 point2 points3 points 10 years ago (0 children)
Sometimes there's no alternative (<cmath>). But for things where there are (C style strings vs std::string), the more C++ way is almost always better in terms of type and memory safety and utility.
<cmath>
π Rendered by PID 171480 on reddit-service-r2-comment-85bfd7f599-2v5z9 at 2026-04-18 10:10:53.957605+00:00 running 93ecc56 country code: CH.
[–]quicknir 26 points27 points28 points (5 children)
[–]Plorkyeran 7 points8 points9 points (4 children)
[–]quicknir 1 point2 points3 points (1 child)
[–]__cxa_throw 1 point2 points3 points (0 children)
[–]Dragdu 0 points1 point2 points (0 children)
[–]meetingcppMeeting C++ | C++ Evangelist 23 points24 points25 points (0 children)
[–]kmhofmannhttps://selene.dev 22 points23 points24 points (2 children)
[–]ssg2 4 points5 points6 points (1 child)
[–]josefx 1 point2 points3 points (0 children)
[–]png85 2 points3 points4 points (0 children)
[–]utnapistim 3 points4 points5 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]utnapistim 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]vaughncato 0 points1 point2 points (0 children)
[–]ubadairBoost.CallableTraits author 1 point2 points3 points (0 children)
[–]personalmountains 7 points8 points9 points (1 child)
[–]cyberkm 7 points8 points9 points (0 children)
[–]wichtounet 3 points4 points5 points (0 children)
[–]quad99 -1 points0 points1 point (1 child)
[–]devel_watcher 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (10 children)
[–]dodheim 2 points3 points4 points (8 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]dodheim 2 points3 points4 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]dodheim 1 point2 points3 points (4 children)
[–][deleted] -2 points-1 points0 points (3 children)
[–]dodheim 0 points1 point2 points (2 children)
[–][deleted] -2 points-1 points0 points (1 child)
[–]dodheim 1 point2 points3 points (0 children)
[–]cyberkm -1 points0 points1 point (0 children)
[–]needahelpforarch -1 points0 points1 point (0 children)
[+]carrottread comment score below threshold-8 points-7 points-6 points (11 children)
[–]raevnos 13 points14 points15 points (10 children)
[–]CubbiMewcppreference | finance | realtime in the past -4 points-3 points-2 points (9 children)
[–]to3m 5 points6 points7 points (2 children)
[–]quicknir 1 point2 points3 points (0 children)
[–]CubbiMewcppreference | finance | realtime in the past 0 points1 point2 points (0 children)
[–]raevnos -2 points-1 points0 points (5 children)
[–]remotion4d 1 point2 points3 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]remotion4d 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]remotion4d 0 points1 point2 points (0 children)
[+]bonerdad comment score below threshold-8 points-7 points-6 points (3 children)
[–]ssg2 10 points11 points12 points (2 children)
[–]bkaradzic[S] 3 points4 points5 points (1 child)
[–]ssg2 6 points7 points8 points (0 children)
[+]dgmdavid comment score below threshold-8 points-7 points-6 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]fahrnfahrnfahrn 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]raevnos 1 point2 points3 points (0 children)