Post Reply 
Passing Arrays?
03-24-2017, 03:40 PM (This post was last modified: 03-24-2017 03:51 PM by toml_12953.)
Post: #1
Passing Arrays?
I'm trying to fill an array in a subprogram. I always get back zeros. What am I doing wrong? Are the parameters passed by value only? If so, is there a way to pass them by reference?

TIA

Tom L

Code:
SET_CONIC( COEF, A, B )
BEGIN
  COEF(1) := A;
  COEF(2) := B;
END;

EXPORT TESTPASS()
BEGIN
  LOCAL C:=MAKEMAT(0,2);   
  SET_CONIC( C, 14, -4 );
  PRINT( C );
END;

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
03-24-2017, 03:47 PM (This post was last modified: 03-24-2017 03:51 PM by Han.)
Post: #2
RE: Passing Arrays?
Both C and COEF are local variables, and therefore their context is restricted to only the subprograms that declare them. Variables are passed by value.

Either declare a local variable outside of the context of the subprograms to hold the coefficient values, or modify your subprogram to return the modified coefficients.

For example:
Code:
// set values of conic coefficient array
SET_CONIC( COEF, A, B, C, D, E, F )
BEGIN
  COEF(1) := A;
  COEF(2) := B;
  COEF(3) := C;
  COEF(4) := D;
  COEF(5) := E;
  COEF(6) := F;
  RETURN(COEF);
END;

EXPORT TESTPASS()
BEGIN

  LOCAL C:=MAKEMAT(0,6);   

  C:=SET_CONIC( C, 14, -4, 11, -44, -58, 71 );
  PRINT( C );
  
END;

or

Code:

COEF:=[0,0,0,0,0,0];

// set values of conic coefficient array
SET_CONIC( A, B, C, D, E, F )
BEGIN
  COEF(1) := A;
  COEF(2) := B;
  COEF(3) := C;
  COEF(4) := D;
  COEF(5) := E;
  COEF(6) := F;
END;

EXPORT TESTPASS()
BEGIN

  SET_CONIC( 14, -4, 11, -44, -58, 71 );
  PRINT( COEF );
  
END;

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-24-2017, 05:23 PM
Post: #3
RE: Passing Arrays?
(03-24-2017 03:47 PM)Han Wrote:  Both C and COEF are local variables, and therefore their context is restricted to only the subprograms that declare them. Variables are passed by value.

Either declare a local variable outside of the context of the subprograms to hold the coefficient values, or modify your subprogram to return the modified coefficients.

For example:
Code:
// set values of conic coefficient array
SET_CONIC( COEF, A, B, C, D, E, F )
BEGIN
  COEF(1) := A;
  COEF(2) := B;
  COEF(3) := C;
  COEF(4) := D;
  COEF(5) := E;
  COEF(6) := F;
  RETURN(COEF);
END;

EXPORT TESTPASS()
BEGIN

  LOCAL C:=MAKEMAT(0,6);   

  C:=SET_CONIC( C, 14, -4, 11, -44, -58, 71 );
  PRINT( C );
  
END;

Thanks! I chose the above method.

Tom L

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
03-28-2017, 05:58 AM
Post: #4
RE: Passing Arrays?
Hello,

Variables are always passed by value. Sorry.

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)