|
On Tue, 27 Mar 2001, Stone, Brad V (TC) wrote: > What's the difference between using CONST and VALUE on ILE parm lists? I > have always used VALUE. It seems to do the same thing as CONST. VALUE copies the contents of the variable into a new area of memory, allowing you to work with it and change it at will without changing the variable on the caller's side. CONST passes the variable by reference (i.e. it passes a pointer to the variable) but flags it as "unchangable". For a string thats 32k long, const still only passes 16 bytes, whereas value would pass 32,000. Perhaps a better way to illustrate the difference is by writing example code: D refTest PR 10I 0 D Parm1 10I 0 D valueTest PR 10I 0 D Parm1 10I 0 value D constTest PR 10I 0 D Parm1 10I 0 const D X S 10I 0 D Y S 10I 0 C** By passing by reference, I'm sending a pointer to X. C** when parm1 is changed, X is also changed since they C** are in the same area of memory. C** c eval X = 1 c eval Y = refTest(X) C* Now X = 2, Y = 2. C** By passing by value, I'm passing the vaue of X. C** when parm1 is changed, X is not affected, it's in C** a different area of memory. The returned value C** is still incremented, since the value was incremented. C** c eval X = 1 c eval Y = valueTest(X) C* Now X = 1, Y = 2. C** By passing by const, I'm passing a pointer to X. C** Since that pointer is flagged as "const", I can't C** change the data in that area of memory. C** Therefore, the constTest() proc won't work at all. C** (in fact, it won't even compile) C** c eval X = 1 c eval Y = constTest(X) c eval *inlr = *on P refTest B D refTest PI 10I 0 D Parm1 10I 0 c eval parm1 = parm1 + 1 c return parm1 P E P valueTest B D valueTest PI 10I 0 D Parm1 10I 0 value c eval parm1 = parm1 + 1 c return parm1 P E ** Note: This won't even compile. You cannot change the ** contents of parm1, since it's passed as const. P constTest B D constTest PI 10I 0 D Parm1 10I 0 const c eval parm1 = parm1 + 1 c return parm1 P E +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
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.