r/cpp • u/Clean-Upstairs-8481 • Sep 27 '26
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.
270
Upvotes
View all comments
Show parent comment
1
u/Spartan322 Oct 16 '26
Okay cool, I really could not care less about violating encapsulation, it can be done, that's the end of it and that's my point, the dogma of encapsulation can take a hike. I sparely use encapsulation, it barely (if at all) exists in C, and too often it gets in my way in C++ to use it as anything more then the occasional tool just the same as how I use singletons and the observer pattern, its great when it doesn't get in my way, worthless when it does. Doing something well and efficient is not subscribing to one paradigm, pattern, or tool, (especially as dogma) and sometimes is actively abandoning the ones that cost you for the workload. And encapsulation is one that's certainly done that to me.