bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: gawk version 3.1.3 and passing a 1-d array into a function + a bug ?


From: Aharon Robbins
Subject: Re: gawk version 3.1.3 and passing a 1-d array into a function + a bug ? + an enhancement
Date: Mon, 29 Dec 2008 22:28:59 +0200

Hi. I think I may have answered this already, but in case I didn't....

> Subject: gawk version 3.1.3 and passing a 1-d array into a function + a bug ? 
> + an enhancement

For what it's worth, 3.1.3, is quite old. You should be using 3.1.6,
which is current, or the code in the gawk-stable CVS repository from
savannah.gnu.org.

> Date: Fri, 7 Nov 2008 14:00:06 -0500
> From: "Brocci, R. A." <address@hidden>
> To: <address@hidden>
> Cc: "Brocci, R. A." <address@hidden>
>
>  To  Arnold Robbinsm or gawk maintainer(s),
>  
> I owe you an apology -- assuming you received my e-mail of 05 Nov, a
> copy of which appears below.
>  
> Shortly after sending this message, I discovered that it appears that I
> have a "function placement" issue, rather than with the function itself.
>  
> That is, the original e-mail message was issued for an ~ 40-record
>  
>     function someName ( N, X )  {
>         for ( I = 1 ; I <= N ; I ++ )  {
>             do my stuff ;
>         }
>         return ;
>     }

I suspect that you are using global variables as if they were locals,
as this is about the only reason for which moving a function around
*might* have any affect. For example, in the above example "I" is a
global variable.

Without actually seeing your program and data, I can't give you any
further advice.

> Possible bug: In the process of this effort, I did encounter what I
> believe is a bug in version 3.1.3 and 3.1.5. Namely, I played with the
>  
>     {
>         if( $0 == ""  ||  match($0,/^[ ]*$/) > 0 )  next ;
>         n = split( $0, A, "," ) ;
>         i = 0 ;
>         while ( i < n )  { X[++i] = A[i] ; print i,A[i],X[i],i ; } 
>     }
>  
> construct, where the { X... } notation is due only to the presence of
> the print statement, which shows that X[1]appears to be A[0], X[2] =
> A[1], etc. (The obvious fix to the above was to use { i++; X[i]... }.)
>  
> Or, have I just tumbled to a violation of the standard after all these
> years?

If I understand you correctly, your concern is the statement

        X[++i] = A[i]

and that you expect X[1] == A[1].  However, this statement isn't portable,
as it's not defined whether the left hand side of the assignment is evaluated
before the right hand side or not. It happens that gawk evaluates the right
hand side first, but you cannot rely on that portably.

> An enhancement: The exitNow command say, whose behavior is like the
> Fortran stop statement or the Perl die command.

This can be done in code; IIRC there's an example in the gawk manual
that shows you how to do this.

> Again, thanks for your time.

You're welcome,

Arnold




reply via email to

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