|
Steve Richter wrote:
When a procedure argument is const, a pointer cannot be set to the argument.
Is it possible to declare a pointer as const in order for the pointer to be
set?
here is an example:
** declare a ds called "Address"
d Address ds qualified
d Street 30a varying
d City 30a varying
d State 2a
d Zip 10a
** proc to print the address
pPrintAddress b
dPrintAddress pi
d InAddress const likeds(Address)
d pStreet s *
/free
pStreet = %addr(InAddress.Street) ;
RplUnprintableChars( pStreet: %size(InAddress.Street)) ;
/end-free
p e
the pointer pStreet cannot be set to InAddress because InAddress is const.
thanks,
No, you can't do that. By declaring a parameter as CONST, you indicate to RPG that you do not intend to modify the parameter. Setting a pointer to the address of the parameter would allow you to change the value of the parameter via a based variable, which violates your promise not to. If you do really want to change the value of the parameter, then define the parameter as a normal reference parameter. Alternatively, copy the value you're interested in to a local variable, and do whatever you want with that. Cheers! Hans
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.