Do pure functions solve the "return const" problems?
Janice Caron
caron800 at googlemail.com
Wed Apr 9 00:11:58 PDT 2008
On 07/04/2008, Christopher Wright <dhasenan at gmail.com> wrote:
> This already works. Why couldn't pure functions do this? You can't tell me.
> You aren't arguing. You are just stating that the compiler can't do
> something that it already does.
Allow me to demonstrate:
int f(out int x) pure
{
x = 1;
return 0;
}
int g(out int x) pure
{
x = 2;
return 0;
}
int h() pure
{
int n;
int t = f(n) + g(n);
return n + t;
}
Question: What does h return?
The problem is, it depends on evaluation order. If f(n) is evaluated
last, h() will return 1, but if g(n) is evalutated last, h() will
return 2. Pure functions are not allowed to depend on evaluation
order, therefore f() and g() cannot be pure - and hence, neither can
h().
My conclusion is that you can't have out parameters in pure functions.
More information about the Digitalmars-d
mailing list