At what point does dereferencing the null pointer become undefined behavior?

I think the second opus of What every C programmer should know about Undefined Behavior might help illustrate this issue. Taking the example of the blog: void contains_null_check(int *P) { int dead = *P; if (P == 0) return; *P = 4; } Might be optimized to (RNCE: Redundant Null Check Elimintation): void contains_null_check_after_RNCE(int *P) … Read more

what is return type of assignment operator?

The standard correctly defines the return type of an assignment operator. Actually, the assignment operation itself doesn’t depend on the return value – that’s why the return type isn’t straightforward to understanding. The return type is important for chaining operations. Consider the following construction: a = b = c;. This should be equal to a … Read more

Why does printing a pointer print the same thing as printing the dereferenced pointer?

Rust usually focuses on object value (i.e. the interesting part of the contents) rather than object identity (memory addresses). The implementation of Display for &T where T implements Display defers directly to the contents. Expanding that macro manually for the String implementation of Display: impl<‘a> Display for &’a String { fn fmt(&self, f: &mut Formatter) … Read more