News for hackers. Stuff that matters.
Re:Essential C [pdf] by Ar-Curunir on Sunday March 06, 2022 @02:52PM (#30580595)
How do you eliminate ub without memory safety?!
Re:Essential C [pdf] by isomel on Sunday March 06, 2022 @04:48PM (#30581597)
For example, as mentioned in another comment, by making all read and write `volatile`, that way, dangling pointer and out of bounds are "defined" to be memory corruption or crash, and not the compiler optimizing the code in a way that the programmer did not enticipate.
Re:Essential C [pdf] by znpy on Sunday March 06, 2022 @05:07PM (#30581749)
Wouldn't that bring a performance penalty though?
Re:Essential C [pdf] by __d on Sunday March 06, 2022 @07:00PM (#30582533)
Yes.

But the current trade-off (performance always wins) means that kernels and other embedded-style programs cannot rely on the compiler doing the "reasonable" thing for UB because it's explicitly allowed to do whatever it wants (which is generally, try for better performance).

For kernel-style work, slightly lower performance but predictable/defined behavior for some of what is currently UB, makes life much simpler.

Re:Essential C [pdf] by Ar-Curunir on Monday March 07, 2022 @01:44AM (#30584858)
You don’t need to do what youre saying for that; Rust provides a way to get both performance and safety
Re:Essential C [pdf] by isomel on Monday March 07, 2022 @02:20AM (#30585055)
Yes. Unless you use `unsafe`. Then the undefined behaviour rules gets even more difficult I'd say.
Re:Essential C [pdf] by __d on Monday March 07, 2022 @03:41AM (#30585512)
Sure, but we're talking about C.