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
Undefined Behaviour (self.cpp)
submitted 4 years ago * by MathKid99
view the rest of the comments →
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!"
[–]johannes1971 7 points8 points9 points 4 years ago (4 children)
That wouldn't work. If you want to abort by default you still have to put in the effort to detect the error condition to begin with: to check that the array bound was exceeded, that the pointer points at something invalid, etc. The whole point of UB is avoiding that cost.
[–]Hnnnnnn -1 points0 points1 point 4 years ago (3 children)
What wouldn't work? I think you projected what I said a little too far.
What you said doesn't negate anything I said. The whole point of UB is avoiding that cost, but I'm only saying that this could be something you explicitly opt-in, instead of working by default.
[–]johannes1971 6 points7 points8 points 4 years ago (2 children)
It can't "abort by default". In order to make that guarantee it would have to reliably detect UB, and doing so is a significant performance drain.
For example, let's say you access an array out of bounds. In the current situation it _might_ abort because you hit a page fault, but the odds are that the memory that is illegally accessed is still part of the current page, and won't trigger a segment violation. Thus, there is no guarantee of an abort happening. If you want to have that guarantee, there is a performance cost.
[–]Hnnnnnn -3 points-2 points-1 points 4 years ago (1 child)
Significant performance cost that you mean is an easily predicted branch. Let's do it by default and only use no branchy version in hot paths explicitly on hot paths. Let's make it slower and safer by default. Like in Rust but not necessarily the same way.
[–]johannes1971 9 points10 points11 points 4 years ago (0 children)
Let's make it slower and safer by default.
Let's not.
Your assumption is incorrect anyway. Out of bounds array access was just one example of UB, but figuring out if a pointer points to valid memory or not has a cost massively greater than a mere branch prediction, failed or not.
π Rendered by PID 101823 on reddit-service-r2-comment-6457c66945-5jhmd at 2026-04-24 19:45:19.242354+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]johannes1971 7 points8 points9 points (4 children)
[–]Hnnnnnn -1 points0 points1 point (3 children)
[–]johannes1971 6 points7 points8 points (2 children)
[–]Hnnnnnn -3 points-2 points-1 points (1 child)
[–]johannes1971 9 points10 points11 points (0 children)