× 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.



There is a problem with passing by const reference that I did not see
mentioned in the recent discussion.

you have a qualified data struct:

d  Cust          ds           qualified
d   Nbr                    6a
d   Name                  30a

and a proc that reads the OrCust database by key and returns a Cust ds:
p  Read_Cust     b
d  Read_Cust     pi
d   InNbr                  6a const
d   OutCust                   likeds(Cust)
 /free
      clear      OutCust ;
      open       OrCust1 ;
      chain      InNbr OrCust1r ;
      close      OrCust1 ;
      if         %found( ) ;
        OutCust  = rCust ;  // trust me.  all the OrCust1 flds are mapped
                            // into a data struct named "rCust"
      endif ;
 /end-free
p                e

** Now this proc is used in code:
d MyCust         ds           likeds(Cust)
 /free
      MyCust.Nbr = 'abc' ;
      Read_Cust( MyCust.Nbr: MyCust ) ;  // will never work like this!!
 /end-free

when the Read_Cust proc is used like so:
  Read_Cust( MyCust.Nbr: MyCust ) ;
the proc call will never work.

when the Read_Cust proc clears parm2, "OutCust", it clears the "MyCust" ds
that was passed by reference to the proc.  Since the input key fld is a
member of that ds, the key is cleared also!

If parm1 of the Read_Cust parm is declared passed by "value", then the proc
does work.

There are other good reasons for passing by value instead of const
reference. Separating the call stack entries from each other as much as
possible is good programming practice.

Passing by const reference should be used with caution and if there is no
performance gain, should not be used.

-Steve Richter



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.