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 15 '26
Okay cool, I'll still tell you to do that, I really don't care to make encapsulation a religious doctrine, I use it when it doesn't get in my way and ignore it when it does. I don't care about using a tool, paradigm, or pattern for a case where it'll hamper me for said case, I have too much experience to know it can do such a thing and I don't care to waste time trying to perfect something over making it good enough.
Encapsulation isn't a principal, its a general guideline with millions of exceptions. Its a tool useful when its reasonable and easy as a solution to uphold, but absolutely useless when its not. Its not an engineering necessity and wasn't even a common premise among many of the older languages initially. Many newer languages also simply don't respect the concept at all either.
It works in the relevant context you devised, so it applies still. I already qualified sure its not as easy as it was before to do, but it can be done, I don't really care about things that get in the way of me producing something that works and is efficient. Would it be nice to use sophisticated tooling to assist me? Sure, if it won't get in my way I might spend some time making it more sophisticated, but as I said, I want something that works and is efficient, I build specialized tooling for my needs and usecases, or I'll use a specialized tool under the Unix philosophy, if that results in me ignoring common paradigms, duplicating code, or doing something thats "less sophisticated" so be it, I'm not trying to build pretty or well structured software, achieving that is a bonus.