bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] getline difference from gawk versions >=4.0.0


From: arnold
Subject: Re: [bug-gawk] getline difference from gawk versions >=4.0.0
Date: Mon, 2 Apr 2012 01:49:48 -0700

Greetings. Re this:

> Date: Sun, 01 Apr 2012 11:49:33 +0100
> From: Duncan Moore <address@hidden>
> To: "address@hidden" <address@hidden>
> Subject: [bug-gawk] getline difference from gawk versions >=4.0.0
>
> Hi
>
> b.awk:
>
> BEGIN {
>    system("echo 1 > f")
>    while ((getline a[++c] < "f") > 0) {}
>    print c
> }
>
> gawk -f b.awk
>
> Prior to gawk 4.0.0 this outputs:
>
> 1
>
> For 4.0.0 and 4.0.1 it outputs:
>
> 2
>
> Regards
> Duncan Moore

This is an interesting test case. I get different answers with different
versions of awk. Brian Kernighan's awk prints 1, mawk prints 2.

It is clearly an artifact of the implementation, although I think that
in this case 2 is the correct answer; the expression creating the "lvalue"
to be assigned for getline should be completely evaluated before getline
is invoked, making getline act more like a function call.

It is probably worth documenting this as Yet Another Dark Corner in
the language.

Thanks!

Arnold



reply via email to

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