3 ms·
> I cannot say I have ever written anything that ran into or caused undefined behavior. And I have programmed for a long time. Assuming you're working with C o
by maccard 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.
Assuming you're working with C or C++, you've never:
- Dereferenced a pointer?
- written a loop with a signed index?
- Accessed an index in an array or a vector?
- Used a variable?
- Used an optimising compiler?
Compilers use undefined behaviour in all of the above scenarios as much as possible, and to do what you likely intended. That's not to say _all_ UB is as reasonable, but a significant amount of what you write relies on some implicit assumptions about UB for a compiler to output reasonable code.
- jstimpfle 4y agoCompilers use reasoning based on UB to optimize and simplify code. But that's not a complete argument why it's highly likely that a given code exhibits UB at run time.
- archi42 4y agoI think they meant "never written UB"? Which would still be a bold claim, much like "I never write bugs" (only features :P).
- tonyarkles 4y agoIn a similar vein to "dereferenced a pointer", "null check on a pointer" is one of those things that often gets optimized out without the developer realizing it.