Running gnu awk I get a div/0 error. Mawk does not have the same error.
>>> awk 'BEGIN { print (0 && (4/0)) }'
awk: cmd. line:1: error: division by zero attempted
>>> mawk ''BEGIN { print (0 && (4/0)) }'
0
If I add parenthesis around the 4 it behaves the same
>>> awk "BEGIN { print (0 && ((4)/0)) }"
0
>>> mawk "BEGIN { print (0 && ((4)/0)) }"
0
Which seems like it should not matter.
Looking through the posix standard I can't actually find the words short circuiting, so are both correct? Just mawk?
The ‘&&’ and ‘||’ operators are called short-circuit operators because of the way they work. Evaluation of the full expression is “short-circuited” if the result can be determined partway through its evaluation.