A
Armen Tsirunyan
Hi all,
Consider the following code:
<CODE>
#include <iostream>
struct X
{
void f()
{
std::cout << "f() called" << std::endl;
}
};
int main()
{
X* p = 0;
p->f();
X x = *p;
x.f();
}
</CODE>
it works( on MSVC9.0), and prints f() called two times. Well,
logically it should, because in X::f() 'this' is not used and
therefore theoretically this could be null; The copy construction also
is logical to succeed because its implicit definition is empty. On the
other hand, if X had a member the copy construction X x = *p woud
fail, because the "this" of the *p would be needed.
Now, my question is,
1. does the standard (the current one) say anything about
dereferencing null pointers?
2. Does the above code result in undefined behaviour?
Consider the following code:
<CODE>
#include <iostream>
struct X
{
void f()
{
std::cout << "f() called" << std::endl;
}
};
int main()
{
X* p = 0;
p->f();
X x = *p;
x.f();
}
</CODE>
it works( on MSVC9.0), and prints f() called two times. Well,
logically it should, because in X::f() 'this' is not used and
therefore theoretically this could be null; The copy construction also
is logical to succeed because its implicit definition is empty. On the
other hand, if X had a member the copy construction X x = *p woud
fail, because the "this" of the *p would be needed.
Now, my question is,
1. does the standard (the current one) say anything about
dereferencing null pointers?
2. Does the above code result in undefined behaviour?