D and expression evaluation order.
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Fri Apr 27 05:19:21 PDT 2007
Bruno Medeiros wrote:
> Frits van Bommel wrote:
>> Bruno Medeiros wrote:
>>> In that case, it is possible for the compiler to detect if the
>>> evaluation order matters, and if it doesn't (currently the only
>>> allowed situation in D), it can push the arguments in any order it
>>> pleases him.
>>
>> <nitpick> Actually, if you check the spec it says the compiler is
>> allowed to issue an error if it detects the _result_ of the expression
>> depends on evaluation order. It doesn't seem to mention side-effects
>> at all, so evaluation order is technically allowed to matter (though
>> it's still an error to _depend_ on it). Well, unless you count
>> side-effects as part of the "result" of an expression... </nitpick>
>
> To "depend on the evaluation order" is to have the evaluation order
> matter. :)
Yes, if you depend on it then it indeed matters.
But the other way around is not necessarily true; I think you can have a
program where evaluation order matters (e.g. different orders produce
different output) without the correctness actually _depending_ on it.
Both orders may be equally correct :).
More information about the Digitalmars-d
mailing list