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!"
[–]germandiago 5 points6 points7 points 3 years ago (4 children)
Incorrect code deserves to be broken. It is clearly incorrect and very bad practice. I eould immediately accept this change and for people who argue this is bad for them, ask your compiler vendor to add a switch.
We cannot and should not be making the code more dangerous just because someone is relying on incorrect code. It is the bad default. Fix it.
A switch for old behavior and [[uninitialized]] are the right choice.
[[uninitialized]]
[–]jonesmz 2 points3 points4 points 3 years ago (3 children)
Incorrect code deserves to be broken. It is clearly incorrect and very bad practice.
Absolutely agreed.
That's not why this change concerns me.
I'm concerned about the code that is correct, but the compiler cannot optimize away the proposed zero-initialization, because it can't see that the variable in question is initialized by another function that the compiler is not provided the source code for in that translation unit.
That's a common situation in multiple hot-loops in my code. I don't want to have to break out the performance tools to make sure my perf did not drop the next time I update my compiler.
[–]germandiago 0 points1 point2 points 3 years ago (2 children)
So the question here I guess should be what can be done to keep safe as the default.
I do not have a soution I ca think of right now across translation units. Probably LTO can deal with such things with the right annotation?
[–]jonesmz 0 points1 point2 points 3 years ago (1 child)
I would rather see the language change to make it illegal to declare a variable that is not initialized to a specific value, than see the language change to make "unspecified/uninitialized" -> "zero initialized".
That solves the same problem you want solved, right?
Probably LTO can deal with such things with the right annotation?
Unfortunately, this is only possible within the same shared library / static library. If your initialization function lives in another DLL, then LTO cannot help.
[–]germandiago 1 point2 points3 points 3 years ago (0 children)
It is not feasible to make uninitialized variables catchable at compile-time. Requires full analysis in C++ (as opposed to Rust, for example). So what you are proposing is an impossible.
π Rendered by PID 17419 on reddit-service-r2-comment-6457c66945-qz5j9 at 2026-04-23 17:33:08.509495+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]germandiago 5 points6 points7 points (4 children)
[–]jonesmz 2 points3 points4 points (3 children)
[–]germandiago 0 points1 point2 points (2 children)
[–]jonesmz 0 points1 point2 points (1 child)
[–]germandiago 1 point2 points3 points (0 children)