1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#include <unistd.h>
#include <math.h>
#define noinline __attribute__((noinline))
class Point
{
private:
void noinline Print(double n);
protected:
double x, y;
public:
Point(double x, double y);
double Norm(void);
};
Point::Point(double x, double y)
{
this->x = x;
this->y = y;
}
// Will be livepatched;
double Point::Norm(void)
{
double n = sqrt(x*x + y*y);
Print(n);
return n;
}
void noinline Point::Print(double n)
{
std::cout << "Point: " << x << ' ' << y << ' ' << "Have norm2 = " << n <<'\n';
}
int main(void)
{
Point p(3, 4);
while (1) {
p.Norm();
sleep(1);
}
return 0;
}
|