bug-gawk
[Top][All Lists]
Advanced

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

[bug-gawk] Sample code in Gawk manual section 9.2.5


From: Hermann Peifer
Subject: [bug-gawk] Sample code in Gawk manual section 9.2.5
Date: Sat, 26 Jan 2013 19:53:36 -0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130107 Thunderbird/17.0.2


Hi,

As far as I can see, the sample code does not work at all with modern gawk, as I end up with this error:

awk: test.awk:3: fatal: attempt to use scalar parameter `a' as an array


> cat test.awk
function foo(a)
{
         a[1] = 1   # parameter is an array
}

BEGIN {
        b=1
        foo(b)  # invalid: fatal type mismatch
        foo(x)  # x uninitialized, becomes an array dynamically
        x = 1   # now not allowed, runtime error
}


> awk -V | head -1
GNU Awk 4.0.72 (GNU MPFR 3.1.1-p2, GNU MP 5.0.5)

I noted that my MacBook's /usr/bin/awk behaves differently:

> /usr/bin/awk --version
awk version 20070501

> /usr/bin/awk -f test.awk
/usr/bin/awk: can't assign to x; it's an array name.
 source line number 10

Hermann



reply via email to

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