×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
On 2023-08-25 6:14 p.m., Barbara Morris wrote:
...
If you're asking about passing the address of a variable by value vs
passing the variable by reference ...
They both behave the same, with the same performance. But passing a
variable by reference is generally good and passing its address by value
is generally bad.
I just want to clarify that my statement about "pass by value" is only
about the general badness of passing the address of a variable by value
vs passing the variable itself by reference. And that's only a problem
for RPG and other languages that don't have typed pointers.
In general, passing parameters by value can be useful. Even passing
pointers by value can be useful sometimes.
I also want to clarify that when calling a program, where parameters are
always passed by reference, passing a pointer-to-a-variable by reference
is slower than passing the variable by reference.
dcl-pr mypgm1 extpgm;
salary packed(9:2);
end-pr;
dcl-pr mypgm2 extpgm;
salary_ptr pointer;
end-pr;
dcl-s salary packed(9:2);
For this call to mypgm1, the compiler puts %ADDR(SALARY) on the
parameter stack.
mypgm1 (salary);
For this call to mypgm2, the compiler puts %ADDR(SALARY) into a
temporary pointer and then it puts the address of the temporary pointer
on the parameter stack.
mypgm2 (%addr(salary)); // The compiler
When mypgm1 is running, to use the SALARY parameter, the compiler
dereferences the parameter-pointer to access the packed(9:2) data.
When mypgm2 is running, to use the SALARY parameter, the compiler first
dereferences the parameter-pointer to get the pointer to the packed(9:2)
data and then it dereferences that pointer to access the packed(9:2) data.
As an Amazon Associate we earn from qualifying purchases.