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

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

bc ; bug in the array parameter mechanizm; FreeBSD4.2R or other


From: Murakami Hiroshi
Subject: bc ; bug in the array parameter mechanizm; FreeBSD4.2R or other
Date: Sat, 16 Mar 2002 19:35:15 +0900 (JST)

/*
Dear,
I believe there is a bug in the unix tool bc.
(I guess this bug originates from the old unix bc.)
The implimentation of array parameters in function definition is
deferent from what I expect from the on line manual "man bc":

   FUNCTIONS
       Functions provide a method of defining a computation  that
       can  be  executed later.  Functions in bc always compute a
       value and return it to the caller.   Function  definitions
       are  "dynamic"  in  the sense that a function is undefined
       until a definition is encountered in the input.  That def-
       inition is then used until another definition function for
       the same name is encountered.   The  new  definition  then
       replaces  the  older definition.  A function is defined as
       follows:
              define name ( parameters ) { newline
                  auto_list   statement_list }
       A  function  call  is  just  an  expression  of  the  form
       "name(parameters)".

       Parameters  are  numbers or arrays (an extension).  In the
       function definition, zero or more parameters  are  defined
       by  listing  their names separated by commas.  Numbers are
       only call by value parameters.  Arrays are  only  call  by
       variable.   Arrays  are specified in the parameter defini-
       tion by the notation "name[]".    In  the  function  call,
       actual  parameters are full expressions for number parame-
       ters.  The same notation is used for passing arrays as for
       defining  array  parameters.  The named array is passed by
       variable to the function.  

*/
#------------------------ cut here ------------------------

/* 
 * This shows the bug in bc.  
 * Try 
 * % bc < thisfile
 * Even I passed the array variable to either function z0 or z1 for
 * the purpose to set the first element to the value of 12345, 
 * after the function is returned, the value in array is lost is found.
 * This makes the array parameter mostly unuseful.
 *          Murakami Hiroshi<address@hidden>
 */


define z0(ar[])
{
        print "z0 entered,\n";
        ar[1]=12345; /* This should set an element of callers array variable*/
        print "inside z0: ar[1]=",ar[1],"\n";
}

define z1(b[])
{
        print "z1 entered,\n";
        b[1]=12345; /* This should set an element of callers array variable*/
        print "inside z1: b[1]=",b[1],"\n";
}


dummy=z0(ar[]); 
print "after z0: ar[1]=",ar[1],"\n";

dummy=z1(ar[]); 
print "after z1: ar[1]=",ar[1],"\n";

/* ======= THE END OF BUG SAMPLE ========*/
#------------------------ cut here ------------------------



reply via email to

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