Re: local variables in a recursive program
Malcolm wrote:
) void zeror(NODE *node)
) {
) static int i;
)
) if(!node)
) return;
) for(i=0;i<node->N;i++)
) node->x[i] = 0;
) zeror(node->left);
) zeror(node-<right);
) }
)
) now there is a point in making i static. Unless the compiler is extremely
) good it won't realise that a separate instance of i is not required for each
) call. So we can handle a rather deeper tree than if i is automatic.
If the compiler is even remotely decent it will put i in a register and
never allocate memory for it in the first place. Making it static might
prevent that from happening.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
|