4 ms·
I really don't get why everyone is so afraid of undefined behavior. It's really not that bad. Learn and use it as another tool, instead of blindly hoping you wo
by dzaima 5y ago
I really don't get why everyone is so afraid of undefined behavior. It's really not that bad. Learn and use it as another tool, instead of blindly hoping you won't encounter it and be surprised when you do. Sure, C has some cases of undefined behavior that are very pointless, but in many cases it's actually useful, and allows anything from faster programs and simpler code, to mapping better to assembly (yes, assembly has undefined behaviors too).
C isn't a language to force you to write guaranteed 100% memory-safe UB-free code. But it's still quite a bit easier to do so in C than assembly for each platform you want to target, and you can get pretty damn close to that assembly you would've otherwise written.
(I in particular do not want any forced memory safety - I've written a custom memory manager with its own semantics of ownership; the language doing anything about safety would just prohibit me doing what I want)
- pjmlp 5y agoMostly because of S in IoT devices. The whole stack is as safe as the weakest link. Then again, we guys in security need job safety anyway.
- dzaima 5y agoThat's pretty much always a problem of memory corruption, which, imo, is very much a separate thing from undefined behavior. Yes, double-free, use-after-free, or reading out-of-bounds is undefined behavior, but -Onone won't make those "better" somehow, and you just can't do anything about it without just completely and utterly changing what C is (and, were that done, some other language would just take its place as an unsafe language that's very nice for trivially making performant code, and we'd be back where we started)
- pjmlp 5y agoNot if liability finally becomes properly regulated. It is like selling food on a shitty street joint, people might keep on doing that, until the day sanitary health check comes around and closes it down.
- dzaima 5y agoI guess all I can say is one man's thrash is another man's treasure. I personally don't have much a reason to care about mamory safety of my programs, so I would hate to have restrictions on what and how I can do things, it would be literally just wasting my time as a programmer, and wasting performance too.