|
"Wilt, Charles" wrote: > ... > But, I did confirm that if you passed a varying(10) variable containing > more than 5 characters to a procedure with a parm defined CONST > varying(5) options(*varsize); the procedure only sees 5 chars and %len > returns 5. > > I was concerned that %len() would return 10 as CONST OPTIONS(*VARSIZE) > usually mean the address of the variable is passed directly; but for a > varying field, the first 2 bytes contain the current length. The > compiler is obviousily smart enough to handle what I was trying > correctly, but I don't know if it is doing some sort of a substr or if > it is moving the varying(10) data to a varying(5) temporarily. > > I suppose it's also possible that %len() doesn't look at the current > length value of a varying field, or the compiler is doing something when > it is used with a CONST VARYING OPTIONS(*VARSIZE) field. > Charles, parameter passing for CONST and VALUE parameters basically works like an EVAL from the passed parameter to the prototyped parameter. If necessary the compiler will actually do an EVAL between the passed parameter and a temporary defined like the prototyped parameter, and then pass the temporary. Basically, the specified parameter is passed only when the called procedure could not detect the difference between the specified parameter and a temporary. (The compiler assumes that the called procedure is going to access the parameter's value legally with respect to the options.) CONST OPTIONS(*VARSIZE) doesn't necessarily say that the address of the parameter is passed directly, even if both passed and prototyped parameters are the same with respect to varying. With const varying parameters, with or without *VARSIZE: if the passed varying parameter might have a current length that is longer than the prototyped parameter, the compiler currently uses a temporary and always assigns the passed parameter to the temporary. It could, if it wanted to, check the length, and if it was not greater, it could just pass the address of the passed parameter.
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.