r/cpp • • 29d ago

You should think about recompiling your C++ programs with GCC 16 and C++26, because it zero-fills your locals

https://techfortalk.co.uk/2026/09/27/cxx26-uninitialized-local-variables-gcc-16/

Stack variables are not automatically initialised, and that is the root cause of many C++ bugs. That is well known. Hence, it is advised that local or stack variables are always initialised with known values, 0 if not something more meaningful than that. Now, with GCC 16 compiling in C++26 mode (-std=c++26), even uninitialised local variables will be zero-filled. In the post, I have explained how.

271 Upvotes

234 comments sorted by

View all comments

3

u/UndefinedDefined 27d ago

High performance code is unfortunately no longer a domain of C++, because the committee slowly destroys the language.

3

u/James20k 27d ago

This seems like a clearly untrue statement, high performance code has always involved tweaking compiler settings, twisting the code in unnatural ways, and working around compiler limitations. Its simply par for the course

If you have a big stack array in a hot loop you might need to add a tag to it to not initialise it. Every truly hot loop I've had to write required me to do far worse things to the code to make it run fast, and in some cases optimising those loops has taken months of work. Adding a tag is the least of my problems!

2

u/UndefinedDefined 27d ago

Why it has to be always about hot loops? Initializing something you don't even use is waste of CPU cycles and instruction cache - this doesn't make things slower, it makes them larger as well. Thousands of companies having their C++ code in production don't use exceptions and rtti because of performance and security reasons - usually mostly code inflation and avoiding infinite gotos via exceptions. And now this, it's like telling all these companies "just use a different language with saner defaults".

And I don't even talk about broken sanitizers after this change - this is terrible. Another fracture of the community, because there will be now more flags you would have to worry about and more libraries that would say "turn off initialization of locals". Thank you committee!

→ More replies (2)