> On 03 Dec 2015, at 1:43, Jens Alfke <j...@mooseyard.com> wrote:
> 
> If x is a value of class/struct X, and y is a non-virtual method, then x.y() 
> turns into X::y(&x).
> 
> So putting the two together, if x is a pointer to X, then x->y() turns into 
> X::y(x). There’s no pointer dereference involved, and no issue if x is NULL. 
> All that happens is that in the implementation of y(), `this` will be NULL.

Is that standard-mandated behaviour or an optimization? If it is legal for any 
member function call to go via the this pointer, then the check is illegal. As 
a practical consideration, in this example (modified from the viva64 post to 
add a data member to the second base class), Xcode 7.1.1 produces a non-null 
this pointer from a null pointer call:

#include <stdio.h>

class FirstBase {
    int firstBaseData;
};

class SecondBase {
    int secondBaseData;
public:
    void Method()
    {
        if( this == 0 ) {
            printf( "this == 0\n");
        } else {
            printf( "this != 0 (value: %p)\n", this );
        }
    }
};

class Composed1 : public FirstBase, public SecondBase {
};

int main()
{
    Composed1* object = 0;
    object->Method();
}

-a
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (Xcode-users@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to