Do pure functions solve the "return const" problems?
Christopher Wright
dhasenan at gmail.com
Sat Apr 5 06:51:31 PDT 2008
Janice Caron wrote:
> On 05/04/2008, Christopher Wright <dhasenan at gmail.com> wrote:
>> Still, there shouldn't be any difference between
>> out parameters and return values.
>
> I think there should. Suppose f is declared:
>
> pure int f(out int n);
>
> Now consider the expression:
>
> f(x) + f(x)
>
> See the problem?
That might be an argument for removing out parameters -- it looks like
f(x) + f(x) is the same as 2 * f(x). The compiler could tell the
difference, so there's no problem on that side. It could basically
rewrite the pretty f(x) + f(x) as the mess you recommended.
You could require the 'out' qualifier at the call site to make it clear
what's going on when you're reading the code. That's probably a better
solution.
More information about the Digitalmars-d
mailing list