bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Handling hexadecimals in different modes


From: Jarno Suni
Subject: Re: [bug-gawk] Handling hexadecimals in different modes
Date: Mon, 7 Sep 2015 01:22:56 +0300

On Mon, 31 Aug 2015 22:56:18 +0300
Jarno Suni <address@hidden> wrote:

> gawk 'BEGIN{printf("%d\n", "0x15")}';
> gawk -W non-decimal-data 'BEGIN{printf("%d\n", "0x15")}';
> gawk -W traditional 'BEGIN{printf("%d\n", "0x15")}';
> gawk -W posix 'BEGIN{printf("%d\n", "0x15")}';
> (prints 0, 21, 0, 21, respectively)

As for non-decimal-data option
https://www.gnu.org/software/gawk/manual/html_node/Nondecimal-Data.html
says:
"Because it is common to have decimal data with leading zeros, and
because using this facility could lead to surprising results, the
default is to leave it disabled. If you want it, you must explicitly
request it.

CAUTION: Use of this option is not recommended. It can break old
programs very badly. Instead, use the strtonum() function to convert
your data (see String Functions). This makes your programs easier to
write and easier to read, and leads to less surprising results.

This option may disappear in a future version of gawk."


But if you want to write portable scripts, strtonum() is hard to
recommend as it is not found in other awk implementation AFAIK.

Could gawk be changed so that with hexadecimal numbers, conversion
would work even without non-decimal-data option or posix option? Then
it would work the same way as other awk implementations I have tested
(i.e. mawk and original-awk in Ubuntu Linux). Oh, I suppose nawk breaks
this rule anyway, as gawk -W traditional tells above, and this below:
http://www.unix.com/302618249-post4.html

-- 
Jarno Ilari Suni - http://www.iki.fi/8/



reply via email to

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