Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: bugs, Bugs and BUGS!

Author: Sune Fischer

Date: 14:47:02 05/29/04

Go up one level in this thread


On May 29, 2004 at 11:33:01, James Swafford wrote:
>>
>>How would you pass arguments to a function in an unevaluated state? Can you draw
>>a stack frame showing exactly what would be done?
>
>The problem (well, Uri's problem) is the order in which the compiler
>evaluates the expression tree.  Think of 'printf' as a node in a tree
>with the parameters as children.
>
>Apparently the children are evaluated first (bottom up), and since
>they share memory, voila...
>
>I think printf could do something like:
>
>While (unevaluated parameter) {
>   evaluate parameter
>   copy results to buffer
>}
>print buffer
>
>Not as efficient, but it would work.
>
>Note I am _not_ saying it _should_ work this way!

From what I understand the problem is not with printf, but in the way parameters
are passed to functions in general.

Eg. if I write F(3*x+4,0.6*y-2), then the program will first evaluate the
argumens and _then_ pass them to the function, F.

It is not possible for the compiler to replace that with two calls like F(3*x+4)
and F(0.6*y-2), because the compiler can't possibly know if F can handle that.

Printf is no exception I think, it gets treated like any other function in this
respect.

-S.
>--
>James



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.