14 Mar, 2009, Keberus wrote in the 1st comment:
Votes: 0
Since, I'm pretty new to the C++ specific things, I was wondering if you have something like:

class blah
{
public:
void fxn( void )
}

void blah::fxn( void )
{
//do something
}


Do you need to check 'this' inside of the function fxn, or merely by the fact that you can do blah->fxn(), does it mean that 'this' is not NULL.

So what I mean, is do I need something like:
void blah::fxn( void )
{
if( !this )
{
bug("%s: NULL this!", __FUNCTION__ );
return;
}
//do something
}



Thanks,
KeB
14 Mar, 2009, David Haley wrote in the 2nd comment:
Votes: 0
Well, I have occasionally seen methods called with a NULL 'this' – it depends on whether the compiler can know what type the pointer is exactly and whether it needs to go to a vtable and so forth. I don't guard against NULL 'this' pointers myself. I consider that you should only call a method on something if you know it's non-NULL, and if you do, you are doing something Very Wrong (TM) and should crash immediately so that you can track it down.
14 Mar, 2009, Keberus wrote in the 3rd comment:
Votes: 0
Alright, I hadn't been doing the checking either, I just wanted to know if I should be.

Thanks for the heads up.
14 Mar, 2009, elanthis wrote in the 4th comment:
Votes: 0
In general, this is never NULL. If it is, there is a more fundamental problem, such as an attempt to call a method on a NULL pointer (which will crash if the method is virtual anyway) or more commonly some kind of memory corruption. Calling a method on a NULL pointer is undefined behavior in the C++ specification.
0.0/4