Re:UndefinedBehaviorSanitizer's Unexpected Behavior
by uecker on Thursday October 17, 2024 @02:46PM
(#41872542)
Every C compiler I ever used will tell you that void()(void) is not convertible to void ()(char). If people still do it then they are a bit on their own. But how is this then different to Rust's "unsafe"? (of course, there is other UB compiler do not tell you about, that this seems a bad example)
Re:UndefinedBehaviorSanitizer's Unexpected Behavior
by im3w1l on Saturday October 19, 2024 @05:22AM
(#41886692)
What if the function is written in assembler and takes some pointer to some opaque memory region?
void (*)(char *) and void (*)(void *) and even void\()(struct SomeStruct*) where SomeStruct is declared but never defined could all be correct and reasonable ways to declare that function in a c-header.
I postulate that almost all UB in the wild comes from the Standard diverging from (often very reasonable) expectations, and I see that as a big problem with the standard, at least as long as compilers can't reliably detect the problem at compile-time. (And yes, C++ is even more problematic here.)
I think one of the reasons Zig exists is that it contains far fewer surprises. The reason Rust exists is that it does a much better job at preventing and containing such surprises.