M
mario semo
Hello,
evaluating
(foo(bar(100.0))) / (foo(bar(10.0)))
i would expect
calculate foo(bar(100.0)
calculate foo(bar(10.0)
divide
(or maybe foo(bar(10));foo(bar(100));reversed divide
but i have a compiler which splits the foo/bar calls to:
reg1=bar(100.0)
reg2=bar(10.0)
foo(reg1)
foo(reg2)
divide
this yields incorrect results in the following sample :
double * bar(double d)
{
static double _sd;
_sd = d;
return &_sd;
}
double foo(double *d)
{
return *d;
}
(the result of 100/10 is 1.)
is this allowed order of subexpr.evaluation or a compiler bug?
Note : some compiler behave different whether foo is a function or a macro:
#define foo(d) (*(d))
evaluating
(foo(bar(100.0))) / (foo(bar(10.0)))
i would expect
calculate foo(bar(100.0)
calculate foo(bar(10.0)
divide
(or maybe foo(bar(10));foo(bar(100));reversed divide
but i have a compiler which splits the foo/bar calls to:
reg1=bar(100.0)
reg2=bar(10.0)
foo(reg1)
foo(reg2)
divide
this yields incorrect results in the following sample :
double * bar(double d)
{
static double _sd;
_sd = d;
return &_sd;
}
double foo(double *d)
{
return *d;
}
(the result of 100/10 is 1.)
is this allowed order of subexpr.evaluation or a compiler bug?
Note : some compiler behave different whether foo is a function or a macro:
#define foo(d) (*(d))