7

Previously, numeric conversions could be triggered by either adding zero (+0), unary plus (+) or unary minus (-):

$ gawk --version
GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.6-p1, GNU MP 6.1.2)

$ gawk 'BEGIN {print "01" + 0}'
1

$ gawk 'BEGIN {print +"01"}'
1

$ gawk 'BEGIN {print -"01"}'
-1

However, now conversion only happens with adding zero and unary minus:

$ gawk --version
GNU Awk 4.2.0, API: 2.0 (GNU MPFR 3.1.6-p1, GNU MP 6.1.2)

$ gawk 'BEGIN {print "01" + 0}'
1

$ gawk 'BEGIN {print +"01"}'
01

$ gawk 'BEGIN {print -"01"}'
-1

Does anyone know where this change was mentioned or why it was done?

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html

  • 5
    FWIW, the awk maintained by Brian Kernighan had that issue where + was a no-op and would not cause conversion to numerical (that's why I recommend to use x+0 here for portability even if + x should work as per POSIX). I did report it to bwk some time ago. It does look like the new behaviour in gawk is not intentional. A comment in the code says // Force argument to be numeric followed by something that doesn't do it. You may want to report it. – Stéphane Chazelas Feb 4 '18 at 23:42
  • 1
    Source code search for 'case Op_unary_plus:' – Isaac Feb 4 '18 at 23:49
  • @StéphaneChazelas fixed now github.com/onetrueawk/awk/commit/32093f5 – Steven Penny Sep 10 '18 at 22:59
6

This is certainly unintentional. We (the gawk maintainers) will look to fix it.

In the future, it would help, A LOT, if such questions were sent to the gawk bug reporting address (bug-gawk@gnu.org, see gawk --help), so that the developers would learn about these issues and fix them.

  • 1
    @Pierre.Vriens As Arnold says, it was unintentional. Unintentional changes can hardly be mentioned in release notes etc. I'm assuming it may be mentioned as a bug fix in the future though, if the authors feel that it's a significant enough bug. – Kusalananda Feb 5 '18 at 15:13
  • 2
    It's tricky to decide whether to send something to the bug-reporting address when you genuinely suspect it might be an intentional change. You could argue that in that case it represents a bug in the documentation, but it's natural to want to minimise the time developers spend triaging non-bugs. – Toby Speight Feb 5 '18 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.