Contents - Index


$DefaultArraySize 

 

This directive sets the maximum array size of the arrays in a Function or Procedure that are specified by indeterminate variables. The format of the directive is

 

$DefaultArraySIze Size FuncName

 

where 

     Size is an integer 

     FuncName is the name of internal Function or Procedure for which the directive is to be applied.  

 

Both Size and FuncName must be supplied.

 

The $DefaultArraySize must appear BEFORE the Function or Procedure statement.  A separate $DefaultArraySize is required for each function or procedure for which it is to be applied.

 

Consider the following EES program that includes internal function Add

 

Function add(N, X[1..N])

  add=0

  i=0

  Repeat

     i=i+1

     add=Add+X[i]

  Until (i>=N)

End

 

N=3

Duplicate i=1,N

  X[i]=i^2

End

ssq=add(N,X[1..N])

 

 

When EES compiles the function, it does not yet know the value of N.  Without knowing N, it is not possible to know that size of the X[1..N] array and thus EES cannot compile the remaining equations that use array X.  So EES sets N to a default value and proceeds to compile the equations.  The default value is normally 100.  If N is set to a value in the main program that is less than the default value, the program will work as expected, although it may reserve variable space that is not needed.  However, if N is set to a value greater than the default value, an error will result.  Try running this program with N set to 101.  

 

One option is to change the Function statement so that N is replaced with its maximum value, e.g., Function Add(N,X[1..120]).  Alternatively, the $DefaultArraySize directive allows the maximum value to be changed, as shown below.  Small values result in less memory use and greater compiler speed, but may result in a error message if the default value is exceeded.  Large values, e.g., 5000, will eliminate the errors but will waste memory and require more computer time.

 

$DefaultArraySize 120  Add

 

Function add(N, X[1..N])

  add=0

  i=0

  Repeat

     i=i+1

     add=Add+X[i]

  Until (i>=N)

End

 

N=101

Duplicate i=1,N

  X[i]=i^2

End

ssq=add(N,X[1..N])

 

 

Directives