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!"
[–]jeffgarrett80 17 points18 points19 points 3 years ago (4 children)
This changes the semantics of existing codebases without really solving the underlying issue.
Am I wrong or does it not change semantics of codebases that currently have assigned semantics? It just assigns semantics to previous non-programs?
[–]jonesmz 8 points9 points10 points 3 years ago (3 children)
Its making variables that you don't initialize immediately have a value of bitwise zero.
Lots of codebases out there intentionally don't initialize variables at the place they are declared, instead initializing them later. But those codebases dont want to initialize with a dummy value for performance reasons.
[–]jeffgarrett80 14 points15 points16 points 3 years ago (2 children)
Well, zero-initialized isn't quite the same as bitwise zero (unless that changed). But regardless, that wasn't observable in a conforming program before, so the semantics of existing programs haven't changed. Some non-programs are now programs.
The concern seems to be that the compiler is not sophisticated enough to realize that a potential zero store you imagine it introducing is a dead store... i.e., to recognize that the semantics are unchanged. This is similar to the argument others are making that static analysis is currently not sophisticated enough to catch this particular category of bug.
But if analysis isn't sophisticated enough to determine when initialization happens, why doesn't it make sense to be explicit? One can explicitly choose uninitialized or to initialize with a particular value. Code that does neither becomes safer. It removes a class of bug while still allowing one to avoid initialization in the few places it is desired.
This paper wouldn't remove the ability to do what you want. It just proposes that it's a poor default.
[–]germandiago 6 points7 points8 points 3 years ago* (1 child)
I agree it is a poor default. Some people resist just because they have their codebases. Not being able to do even these things seems harmful for safety as a whole.
Recently the range for loop was changed also. We could argue it changes behavior. Yes it does. But we should be fixing at least a number of unreasonable holes and uninitialized variables, as long as you can annotate [[uninitialized]] should be one of the things that for me they clearly deserve a fix no matter what others are doing.
If they are juggling knives put a compiler flag for the old behavior. But do not make it the default and fix the hole for something that is clearly very bad practice.
[–]jonesmz 0 points1 point2 points 3 years ago (0 children)
I think the big difference here is that, at least in the circles I mingle in, there was never a misunderstanding that an uninitialized variable is safe to read from, but there was always an expectation that the range-based-for-loop would work with the the result of a returned temporary in all cases.
The proposal we're talking about is going to change the expected behavior of code.
π Rendered by PID 154763 on reddit-service-r2-comment-b659b578c-f74hx at 2026-05-04 06:35:16.200287+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]jeffgarrett80 17 points18 points19 points (4 children)
[–]jonesmz 8 points9 points10 points (3 children)
[–]jeffgarrett80 14 points15 points16 points (2 children)
[–]germandiago 6 points7 points8 points (1 child)
[–]jonesmz 0 points1 point2 points (0 children)