Re:Falsehoods programmers believe about undefined behavior
by archi42 on Monday November 28, 2022 @08:16AM
(#33773231)
I think they meant "never written UB"? Which would still be a bold claim, much like "I never write bugs" (only features :P).
Re:Falsehoods programmers believe about undefined behavior
by jstimpfle on Monday November 28, 2022 @08:09AM
(#33773159)
Compilers 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.
Re:Falsehoods programmers believe about undefined behavior
by tonyarkles on Monday November 28, 2022 @11:02AM
(#33775265)
In 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.
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.