I'm getting strange results when attempting to de-allocate a static based variable. Below is a small test program I've created to demo the issue I'm having. The static based variable is in the proc1 sub-procedure of this test program. Its name is myIx, with based pointer of myIx_p. I put comments in the main body of the program to indicate the issues that I'm having. What am doing wrong here?
D ix s 5i 0
/free
ix = proc1(*off); // ix is 1 after this statement => Expected
ix = proc1(*off); // ix is 2 after this statement => Expected.
ix = proc1(*on); // ix is 0, which is expected. But myIx_p is not being set to null => NOT Expected
ix = proc1(*off); // ix is 3 after this statement => NOT Expected. Expecting 1.
ix = proc1(*on); // try to shutdown again and get CEE0810 error => NOT Expected
*inlr = *on;
*------------------------------------------------------------------------------------------
* proc1 to test based static variable
*------------------------------------------------------------------------------------------
P proc1 B
D pi 5i 0
D piShutDown n const
D myIx s 5i 0 based(myIx_p)
D myIx_p s * static
// caller only wants to shutdown the proc
if (piShutDown and myIx_p <> *null);
dealloc myIx_p;
return 0;
endif;
// allocate myIx if not yet allocated
if (myIx_p = *null);
myIx_p = %alloc(%size(myIx));
endif;
// increase the value by 1 as a test
myIx += 1;
return myIx;
P E
/end-free