Thank you very much for your answer.
<miaohua1982@gmail.com> wrote in message
news:1168001092.497006.152700@51g2000cwl.googlegroups.com
the code is as follows:
#include<iostream>
using namespace std;
class A
{
public:
int a;
int b;
};
int main(int argc,char **argv)
{
int (A::*pInt) = &A::a;
if ( &A::a )
{
cout<<"OK1n"<<endl;
}
if( pInt)
{
cout<<"OK2"<<endl;
}
return 0;
}
Yes, looks like a codegen bug to me. Looking at disassembly, a
pointer-to-member is stored simply as offset from the beginning of the
class. In particular, the first data member is usually at offset 0 (as
it is in this example), and pointer to it is represented as four zero
bytes.
Since all-zeros is a valid pointer-to-member, a NULL pointer-to-member
is stored as 0xFFFFFFFF. When checking a variable, as in "if (pInt)",
the compiler correctly generates code that compares the value with
0xFFFFFFFF. But in the statement "if (&A::a)" the compiler checks
against 0x0, and that's a bug.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925