bug-gawk
[Top][All Lists]
Advanced

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

Re: too many arguments lint warning - should it be standard?


From: Ed Morton
Subject: Re: too many arguments lint warning - should it be standard?
Date: Tue, 18 Feb 2020 11:13:36 -0600
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2

OK, thanks for looking into it.

    Ed.

On 2/17/2020 10:47 PM, address@hidden wrote:
Thanks for the note.

Every awk implementation I have tried silently accepts the extra
argument.  I think it would break compatibility to turn this warning
on by default, however useful that might otherwise be.  Instead,
just run with --lint all the time (set an alias or script). If your
code is clean, you won't get any complaints. :-)

Thanks,

Arnold

Ed Morton <address@hidden> wrote:

I just wrote this code with a bug in it where I used a `,` instead of a
`;` after the printf data argument:

     awk -v x=5 '{printf "%s\n", x, x=7}'

My intent was to print a `5` for the first input line and then `7` for
subsequent lines so what I MEANT to write was:

     awk -v x=5 '{printf "%s\n", x; x=7}'

Note the semi-colon in `x; x=` vs the comma `x, x=`. I didn't notice the
bug for a while because the code with the bug actually produces the
expected output:

     $ seq 3 | awk -v x=5 '{printf "%s\n", x, x=7}'
     5
     7
     7

with no complaints. When I ran with lint enabled I did get a warning:

     $ seq 3 | awk --lint -v x=5 '{printf "%s\n", x, x=7}'
     awk: cmd. line:1: (FILENAME=- FNR=1) warning: too many arguments
     supplied for format string
     5
     awk: cmd. line:1: (FILENAME=- FNR=2) warning: too many arguments
     supplied for format string
     7
     awk: cmd. line:1: (FILENAME=- FNR=3) warning: too many arguments
     supplied for format string
     7

So - should that warning appear by default rather than just when
`--lint` is added or is there some scenario where having more arguments
than the format string takes would be deliberate/useful?

I'm running gawk 5.0.1 on cygwin.

Regards,

       Ed.




reply via email to

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