Здравствуйте VVV, Вы писали:
DG>Должен ли по стандарту работать следующий код?
struct SA
{
void Func() //невиртуальная
{
if (this == NULL)
return;
}
static void StaticFunc() {}
};
void main()
{
((SA*)0)->StaticFunc(); //ИМХО, тут должно быть все нормально
((SA*)0)->Func(); //а вот здесь не понятно, мало ли чего может компилятор напихать
}
VVV>если бы Вы привели конкретное место в стандарте (хотя бы ссылку) может быть этой дискуссии и не было бы
Андрей прав. Закрываем дискуссию, вот соответствующие выдержки из стандарта:
5.2.5 Class member access (expr.ref)
1 A postfix expression followed by a dot . or an arrow ->, optionally followed by the keyword template (14.8.1), and then followed by an idexpression, is a postfix expression. The postfix expression before the dot or arrow
is evaluated; 58) (...)
58)
This evaluation happens even if the result is unnecessary to determine the value of the entire postfix expression, for example if the idexpression denotes a static member.
3 If E1 has the type “pointer to class X,” then the expression E1->E2 is converted to the equivalent form
(*(E1)).E2; (...)
1.9 Program execution (intro.execution)
4 Certain other operations are described in this International Standard as
undefined (for example, the effect of
dereferencing the null pointer).
8.3.2 References (dcl.ref)
4 (...) [Note: in particular, a null reference cannot exist in a welldefined program, because the only way to create such a reference would be to bind it to the “object” obtained by
dereferencing a null pointer, which
causes undefined behavior. (...)
Легче одурачить людей, чем убедить их в том, что они одурачены. — Марк Твен