[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why 'statement may have no effect' lint warning here?
From: |
arnold |
Subject: |
Re: Why 'statement may have no effect' lint warning here? |
Date: |
Mon, 12 Apr 2021 06:52:03 -0600 |
User-agent: |
Heirloom mailx 12.5 7/5/10 |
Hi.
arnold@skeeve.com wrote:
> > But if function call is used instead of 'var == 1' the warning is
> > gone:
> >
> > BEGIN {
> > var = 1
> > print("hi") && var = 3
> > print "var ==", var
> > }
>
> I need to investigate this further. In particular, none of gawk,
> mawk or Unix nawk execute the print statement. Technically,
> print isn't a function, it doesn't return a value. But none of the
> three issue an error message about its use in an expression.
When the light went on, it was blinding.
-- Ed Nather
The use of print here isn't a problem. It's not doing what it
looks like at first glance. Remember that in awk, print doesn't
have to have parenthesized arguments:
print a, b, c
or even
print a
are fine. In the general sense, this is
print expression
In the case of
print("hi") && var = 3
the expression is
("hi") && var = 3
It's as if it were typed
print (("hi") && var = 3)
(and thus it prints a 1). This also explains why there is
no lint error.
HTH,
Arnold
- Why 'statement may have no effect' lint warning here?, Arkadiusz Drabczyk, 2021/04/11
- Message not available
- Re: Why 'statement may have no effect' lint warning here?, Manuel Collado, 2021/04/13
- Re: Why 'statement may have no effect' lint warning here?, Wolfgang Laun, 2021/04/13
- Re: Why 'statement may have no effect' lint warning here?, Manuel Collado, 2021/04/13
- Re: Why 'statement may have no effect' lint warning here?, arnold, 2021/04/14
- Re: Why 'statement may have no effect' lint warning here?, Wolfgang Laun, 2021/04/14