3 ms·
I especially love that piece of guidance because there isn't a good way of testing whether a pointer is invalid. Imagine I'm a function and I've got a pointer
by UncleMeat 4y ago
I especially love that piece of guidance because there isn't a good way of testing whether a pointer is invalid.
Imagine I'm a function and I've got a pointer to some object. I know the object is owned by something else. Let's say I want to be extra safe and check whether the pointer is valid before accessing it. How do I do this? I cannot dereference it. I can't compare it against something useful. I could have a custom allocator that tracks the status of all allocated and freed regions of memory, cast my pointer to a void pointer, and check with the allocator (I think this isn't UB). But now I've also got to make sure that freed regions of memory are never reused for any reason. Thanks Bjarne.