Code Comments
Programming Forum and web based access to our favorite programming groups.The question has to do with the (new?) type Node_var_new. I'm curious as to when this type was added and what its purpose is. I had made some modifications to gawk in earlier versions (maybe 3.0.6) and did not have to deal with this, but now I tried making the same mods to 3.1.4 and found that if type is Node_var_new, you have to change it to Node_var - after which all is as before. Can anyone tell me why this change was made?
Post Follow-up to this messageIn article <cod4bc$df5$1@yin.interaccess.com>,
Kenny McCormack <gazelle@accessinter.combat> wrote:
>The question has to do with the (new?) type Node_var_new.
>
>I'm curious as to when this type was added and what its purpose is.
>I had made some modifications to gawk in earlier versions (maybe 3.0.6) and
>did not have to deal with this, but now I tried making the same mods to
>3.1.4 and found that if type is Node_var_new, you have to change it to
>Node_var - after which all is as before. Can anyone tell me why this
>change was made?
It helps in tracking uninitialized variables and function parameters.
Particularly for function parameters, whose type can change on the
fly:
BEGIN { f(a) }
function f(p) { p[1] = "x" }
Gawk can't tell that global variable `a' is really supposed to be an
array until after f() has run.
--
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd. arnold AT skeeve DOT com
P.O. Box 354 Home Phone: +972 8 979-0381 Fax: +1 206 350 8765
Nof Ayalon Cell Phone: +972 50 729-7545
D.N. Shimshon 99785 ISRAEL
Post Follow-up to this messageHi,
> Kenny McCormack wrote:
Arnold has explained most of it. I'd like to point out a few gotchas:
You should also initialize it to an uninitialized value:
tree->type = Node_var;
tree->var_value = Nnull_string;
This is best illustrated by make_scalar() in eval.c.
Also note that under some circumstances, you may encounter Node_array_ref
where you'd expect Node_var. For example:
function f(x) { x = 1 }
BEGIN { f(a) }
After you enter the function, ``a'' is of type Node_var_new and ``x'' is
of type Node_array_ref.
After the assignment is executed, both are changed to Node_var, since
make_scalar() has been called with the ``x'' node as parameter.
To sum up, you code has to take care of Node_array_ref's, unless you take
care to initialize all variables before passing them to a function.
HTH,
Stepan Kasal
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.