visual studio 2010 - Undefined behaviour in C++ asserts: accessing an invalid/null pointer -
under visual c++ 2010, following snippet hides dubious behaviour:
cobject* myobjectptr = cobjectfactory::makeanobject(); assert( myobjectptr->candosomework() ); // myobjectptr can null due logical errors
the following snippet, when placed in function, did not trigger assert when pointer null , function returned immediately. aside null pointer check obvious fix suggest, made code behave in such way? shouldn't complain memory access violation error if error occurs within assert?
myobjectptr->candosomework()
if candosomework not virtual function compiler rewrites c_object::candosomework(myobjectptr)
this doesn't involve dereference of object pointer @ won't crash or fail. if it's virtual function crash use pointer find vtable.
of course none of guaranteed in standard, it's undefined behavour, explains seeing happen.