4 ms·
> I cannot say I have ever written anything that ran into or caused undefined behavior. And I have programmed for a long time. Perhaps this is true, or perhaps
by MushyQuadrant 4y ago
> I cannot say I have ever written anything that ran into or caused undefined behavior. And I have programmed for a long time.
Perhaps this is true, or perhaps you are just unaware of the undefined behavior you have relied on.
What I can say for sure, is that all of the non-trivial C++ programs written by a large team which I have worked on in my career have invoked some undefined behavior. Usually, the compiler does do "the right thing" despite the error, but sometimes it blows up in our face, and causes incredibly hard to debug bugs, such as a pointer appearing to simultaneously point to two different addresses, because an array was declared as two different sizes in two different translation units.
Even when I spot the instances of undefined behavior, it's often hard to convince other developers that, although this seems to behave correctly now, it could break in unexpected, hard to debug ways at any time in the future.