[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Indexing Arrays with number which have leading zero behav
From: |
arnold |
Subject: |
Re: [bug-gawk] Indexing Arrays with number which have leading zero behaves unexpected |
Date: |
Sun, 03 Jun 2018 11:27:36 -0600 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Andy's analysis and pointers are on target. It is the treatment
of a leading 0 as octal that most likely causing the confusion.
Thanks,
Arnold
"Andrew J. Schorr" <address@hidden> wrote:
> Hi,
>
> On Sun, Jun 03, 2018 at 09:54:43AM +0000, Kolbe, Wulf wrote:
> > please find enclosed a small program which shows an effect during indexing
> > arrays with numbers which have leading zeros.
> > It behaves at least unexpected for me, because of the behavior changes
> > during increasing the index number.
> > If you run all numbers from 000-to255, then it works between 000-064, then
> > there is a gap of approx. 16 places and then it works again.
> >
> > BEGIN{
> > B[04]=2; printf("%d\n",B[4]);printf("%d\n",B[04]);
> > B[064]=42; printf("%d\n",B[64]);printf("%d\n",B[064]);
> > }
> >
> > This effect was found on CoCalc Clouds gawk 4.1.3 but also verified on a
> > lot of older versions.
> > The leading zeros were written to visually inspect lists with values like
> > palette definitions and there the effect shows as funny gab in the palette.
>
> What effect are you talking about? What is your expected behavior, and
> how does that compare to what actually happens?
>
> There are two things to keep in mind here:
>
> 1. All array subscripts are strings.
>
> https://www.gnu.org/software/gawk/manual/html_node/Numeric-Array-Subscripts.html
>
> 2. Numerical constants that start with "0" are considered to be octal values.
>
> https://www.gnu.org/software/gawk/manual/html_node/Nondecimal_002dnumbers.html
>
> I think some combination of these two factors should probably explain the
> behavior you are seeing. If not, then there is a bug.
>
> For example, using current gawk 4.2.1:
>
> bash-4.2$ gawk 'BEGIN {B[064] = 42; for (i in B) print i, typeof(i)}'
> 52 string
>
> Can you please explain further what you think is not working correctly?
>
> Regards,
> Andy