|
"Christen, Duane J." wrote: > > I just came across an interesting bug in my code. (see below) I have a > function which returns a value and assigning that value to an array element. > I had not indexed the array correctly so the function was being "called" for > each element. It was finally failing because not all of the storage for the > array was allocated. I assume, altho I have not tried it, that if the array > would have been fully allocated that all elements would have been assigned a > return value from individual function calls. > > The question would be: Is this an intended feature and can I expect this > result in the future? > I'm currently on V5R2M0. > In general, if you do "array=value", every element gets the value. When "value" includes a call, the call gets made every time. The exception is for "array=arrayproc"; a procedure returning an array is only called once. I'm not sure about "intended feature", but this is the expected behaviour. Changing it would introduce an incompatibility if the called procedure has side-effects; for example, it reads a file and returns a different record on every call (I don't particularly think this is a good thing to do, but it's possible). A prototype keyword indicating that a procedure has no side effects would be useful. Barbara ===
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.