bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SYMTAB update inside function calls


From: arnold
Subject: Re: SYMTAB update inside function calls
Date: Mon, 11 Dec 2023 11:41:36 -0700
User-agent: Heirloom mailx 12.5 7/5/10

Hello.

It's not a bug. The parameters shadow the global variables. Try
this version:

$ cat /tmp/x.awk
function foo(x, y, z) {
  d = -1
  printf("inside foo: c is %s, d is %s\n", typeof(c), typeof(d))
  SYMTAB["c"] = x + y
  SYMTAB["d"] = x * y
  printf("inside foo: c=%d, d=%d\n", c, d)
}

BEGIN {
  a = 2
  b = 3
  c = 1
  foo(a, b, c)
  printf("outside foo: c=%d (%s), d=%d (%s)\n", c, typeof(c), d, typeof(d))
}

$ gawk -f  /tmp/x.awk
inside foo: c is number, d is number
inside foo: c=5, d=6
outside foo: c=5 (number), d=6 (number)

Arnold

M <c24p0101@gmail.com> wrote:

> Hi!
> A quest for you all :)
>
>
> From: userland
> To: bug-gawk@gnu.org
> Subject: SYMTAB update inside function calls
>
> Configuration Information [Automatically generated, do not change]:
> Machine: aarch64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS: -g -O2 -DNDEBUG
> uname output: Linux localhost 4.19.113-perf-g01b4c0bc6315 #1 SMP PREEMPT
> Tue Nov 1 23:34:34 CST 2022 aarch64 GNU/Linux
> Machine Type: aarch64-unknown-linux-gnu
>
>
> Gawk Version: 5.3.0
>
> Attestation 1:
> I have read https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
> Yes
>
> Attestation 2:
> I have not modified the sources before building gawk.
> True
>
> Description:
> I noticed the creation or modification of values using SYMTAB doesn't works
> inside a function call, *only* if the variable to be update is a function
> parameter.
>         SYMTAB seems to be update only at funcion exiting.
>
> Repeat-By:
> [userland@localhost ~]$ cat s.awk
>
> function foo(a, b, c) {
>   d = -1
>   printf("inside foo: c is %s, d is %s\n", typeof(c), typeof(d))
>   SYMTAB["c"] = a + b
>   SYMTAB["d"] = a * b
>   printf("inside foo: c=%d, d=%d\n", c, d)
> }
>
> BEGIN {
>   a = 2
>   b = 3
>   c = 1
>   foo(a, b, c)
>   printf("outside foo: c=%d (%s), d=%d (%s)\n", c, typeof(c), d, typeof(d))
>
> }
> [userland@localhost ~]$ AWK/gawk/gawk -f s.awk
> inside foo: c is number, d is number
> inside foo: c=1, d=6
> outside foo: c=5 (number), d=6 (number)
> [userland@localhost ~]$
>
> Fix:
>     Don't sure is a bug, albeit an unexpected behaviour. I've not found
> mentions of this in the documentation, if I'm not wrong maybe a note should
> be added there.
>
>
>
>
>
>
>
>  me -> http://crap0101.altervista.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]