Home > Archive > AWK > December 2004 > GAWK implementation (source code) question (change noticed in 3.1.4)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
GAWK implementation (source code) question (change noticed in 3.1.4)
|
|
| Kenny McCormack 2004-12-02, 8:55 pm |
| 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?
| |
| Aharon Robbins 2004-12-03, 3:56 am |
| In 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
| |
| Stepan Kasal 2004-12-07, 3:59 am |
| Hi,
[color=darkred]
> Kenny McCormack wrote:
Arnold has explained most of it. I'd like to point out a few gotchas:
[color=darkred]
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
|
|
|
|
|