// Test program for strange -O2 optimization issue
// For details, see this post:
// http://gcc.gnu.org/ml/gcc-help/2008-08/msg00004.html
#include <cstdio>

struct Point
{
public:
    double x;
    double y;
    double getX() const { return x;}
    double getY() const { return y;}
};
static unsigned long HashDouble(double* pdfVal)
{
    unsigned int* pnValue = (unsigned int*)pdfVal;

    // printf("%p\n", pnValue); // Seems to fix the problem

    return pnValue[0] ^ pnValue[1];
}
static unsigned long HashPoint(const Point* point)
{
    double x = point->getX();
    double y = point->getY();
    return HashDouble(&x) ^ HashDouble(&y);
}
int main()
{
    Point* po = new Point();
    po->x = 1;
    po->y = 2;

    for (int i = 0; i < 5; ++i)
    {
        std::printf("%lu\n", HashPoint(po));
    }
    delete po;
    return 0;
}


