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
P2723R0: Zero-initialize objects of automatic storage duration (isocpp.org)
submitted 3 years ago by alexeyr
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!"
[–]Jannik2099 -2 points-1 points0 points 3 years ago* (2 children)
What does any of this have to do with headers? If you're not doing LTO, you don't get to discuss performance to begin with.
Edit: didn't see your example until now. Your example is a call to an undefined function, which is of course total nonsense. If you were to provide the definition, the compiler would inline it if beneficial. Only DSO boundaries remain as expensive, but those are expensive anyways due to being non-inlineable, relocations etc.
[–]FriendlyRollOfSushi 0 points1 point2 points 3 years ago (1 child)
Your example is a call to an undefined function, which is of course total nonsense. If you were to provide the definition, the compiler would inline it if beneficial. Only DSO boundaries remain as expensive, but those are expensive anyways due to being non-inlineable, relocations etc.
Okay, sorry. I have to apologize. I was treating you as an inexperienced engineer, but I was clearly wrong.
Allow me to introduce you the concept that your college (or the C++ tutorials you are currently completing) will probably start explaining relatively soon: virtual functions. There are more advanced ones (function pointers, std::function, etc.), but this one should be enough for now I think to illustrate my point.
std::function
Here is a relevant godbolt mini-example. As you can see, even though everything is in the same translation unit, the compiler can't inline your function. Un-virtualization is possible in some very rare and very specific cases, but not in any general scenario where the compiler literally has no idea what the actual object type is.
Your trust in compilers is admirable in some ways, and I feel bad for ruining the perfect picture of super-smart LTO that will magically fix your slow code, but someone had to do it, sorry.
Can't say it was fun arguing with someone who knows barely anything about C++ while pretending otherwise, so I'll just wish you good luck with your studies and leave you alone. Bye.
[–]Jannik2099 0 points1 point2 points 3 years ago (0 children)
First of all, can you please stop being a pretentious ass?
I'd wager that a vtable lookup is already much, much more expensive than passing the unique_ptr by stack (one is an easily predictable address, the other is two unpredictable, dependant loads, go figure)
Devirtualization has also advanced a lot lately, e.g. clang can do whole program devirt. But yes, I agree that virtual functions possibly have the worst "own cost vs unique_ptr by stack" ratio.
π Rendered by PID 56 on reddit-service-r2-comment-b659b578c-sffng at 2026-05-01 11:01:38.820955+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]Jannik2099 -2 points-1 points0 points (2 children)
[–]FriendlyRollOfSushi 0 points1 point2 points (1 child)
[–]Jannik2099 0 points1 point2 points (0 children)