Do pure functions solve the "return const" problems?

Janice Caron caron800 at googlemail.com
Fri Apr 11 00:00:20 PDT 2008


On 11/04/2008, Christopher Wright <dhasenan at gmail.com> wrote:
> The results of these functions is independent of the order in which they are called.

How do you define "results"?

I ask because, if you mean "that which is returned through the return
statement", then maybe so, but if you include the out variables
themselves as part of the "results" then that statement is false, as
my previous counterexample shows.



>  It should, however, suffice to say that such things are undefined behavior,
> as they currently are.

Look at it another way:

    int f(out int r, int n)
    {
        r = something;
        return somethingElse;
    }

is exactly equivalent to:

    int f(int* r, int n)
    {
        *r = something;
        return somethingElse;
    }

The latter would not be considered a pure function. Therefore, nor
would the former.



More information about the Digitalmars-d mailing list