4 ms·
I believe you are correct as per a summary at https://stackoverflow.com/questions/60147025/is-converting-an-integer-to-a-pointer-always-well-defined https://sta
by shadowgovt 2y ago
I believe you are correct as per a summary at https://stackoverflow.com/questions/60147025/is-converting-an-integer-to-a-pointer-always-well-defined https://stackoverflow.com/questions/60147025/is-converting-a...
- compiler-guy 2y agoThat summary talks about creating a nullptr out of an int, but not dereferencing it. And, in fact, takes care to note that dereferencing the created pointer is invalid.
- shadowgovt 2y agoBut using an invalid pointer is implementation-dependent, not UB, unless I'm missing a step here?
- compiler-guy 2y agohttps://en.cppreference.com/w/cpp/language/pointer https://en.cppreference.com/w/cpp/language/pointer Nullptr section is not directly linkable, but: "A pointer whose value is null does not point to an object or a function (the behavior of dereferencing a null pointer is undefined), and compares equal to all pointers of the same type whose value is also null."
- shadowgovt 2y ago`p = reinterpret_cast<int*>(42);` doesn't create a nullptr.
- compiler-guy 2y agoThe gp example does, however.
- int_19h 2y agoIt is UB in ISO C23 (6.5.4.2/4). I'm pretty sure there's equivalent verbiage in ISO C++.