While doing programming i am using assert as well as NULL pointer validation.
But as i know assert will be useful only in DEBUG mode.
My question is suppose i have a internal pointer which i am sure cant be NULL example function returning a pointer(but the pointer is not a member of class) in such cases i can use assert
test* ptr = fun(); // return a pointer of type test
assert(ptr);
//do some operation
or NULL pointer validation
test* ptr = fun(); // return a pointer of type test
assert(ptr);
if (NULL != ptr)
{
//do some operation
}
Here which code practice is good.As per my understating it will be second one. Because i have faced some situations where the value of ptr returns NULL due to some abnormal cases that we cant even think of.
But do we have any other better options?