|
Hi Hans, Scott, Jim, Ok, so actually, a CONST parameter is passed by reference, but by noting CONST, the *compiler* will check to make sure I don't modify the parameter in my procedure, correct? Also, sometimes a CONST parm will be a copy, although in the circumstances mentioned by the manual ("the passed parameter is an expression or the passed parameter has a different format") I'm not sure I'd exactly call that a copy. And when passing by VALUE, it *always* makes a copy of the data, then passes that copy by reference? I.e. a pointer is pushed on the stack for the copy? Are there any parameter-passing situations where actual data is pushed onto the stack? In this case, the compiler will allow me to modify the parameter, but the calling program never sees those modifications because it never sees the copy. Assuming I've got that right, why didn't my procedure work? Is the problem that VALUE does not convert the data to the parameter's size and type like CONST does? In that case, what Jim said must be the problem, and it was just happenstance that there were blanks out to pos.1024. I'm looking forward to V5R1, but from where I sit it's hard to say when that will happen. tia, Peter Dow Dow Software Services, Inc. 909 425-0194 voice 909 425-0196 fax ----- Original Message ----- From: <boldt@ca.ibm.com> Sent: Thursday, December 13, 2001 11:33 AM Subject: Re: Procedure parameter with VALUE option > Peter wrote: > >I'd really like to know what's going on, and where > >it's appropriate to use VALUE instead of CONST. > > VALUE and CONST should be used when passing parameters to > procedures where the procedure does not change the value > passed. Reference parameters are used when you want the > procedure to change the value of a particular variable. > > How to choose between VALUE and CONST? CONST parameters > are like reference parameters in that an address is pushed > on the stack. (CONST parameters must not be changed > within the procedure. VALUE parameters can be changed > within the procedure, without affecting any variable > passed in the call.) So, one rough rule of thumb is that > if the item is bigger than a pointer, use CONST, otherwise, > use VALUE. > > But it's not quite that simple. For example, I recently > posted a sample procedure for centering text on the RPG > forum at the iseriesnetwork.com web site. I chose to > pass the varying length string parameter by VALUE. Why? > Because the first thing my procedure did was %TRIM the > string. By passing the string by VALUE, I was able to > change the value of the string parameter, and I didn't > need to define a separate variable within the procedure. > It made the coding of the procedure a bit easier. > > Generally though, strings should be passed as CONST > VARYING. Smallish items should be passed as VALUE. If > you need to return a value from a procedure, use the > the RETURN opcode. If you need to return multiple values, > you might be tempted to define several reference > parameters. But I'd recommend returning a data structure > instead. In V5R1, that has been made much easier now that > you can code LIKEDS as the type of the return value. _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
As an Amazon Associate we earn from qualifying purchases.
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.