× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



One interesting side effect of using CONST:
If you pass a global variable as CONST parameter to a procedure within the
same module, that procedure can modify the parameter by changing the global
variable. Sounds crazy, until you realize that all database fields are
global variables. I once had a procedure that received a database field as a
CONST parameter and then read another record from the same file. Good to
have a debugger.

Joep Beckeringh

----- Original Message -----
From: "Joe Pluta" <joepluta@xxxxxxxxxxxxxxxxx>
To: "'RPG programming on the AS400 / iSeries'" <rpg400-l@xxxxxxxxxxxx>
Sent: Thursday, August 07, 2003 10:03 PM
Subject: Value vs. Const


> Okay, I know the issue was discussed not too long ago, but I'm trying to
> make sure I understand.  I'm going full bore with procedures right now
> and I'm trying to decide which to use, VALUE or CONST.
>
> It's my understanding that either keyword prevents a parameter from
> being modified by the called procedure.  I seem to recall reading that
> with CONST, not even the local copy can be modified, while with VALUE,
> the local copy can be modified, but won't be passed back.
>
> Thus, a side effect of either keyword is that the compiler can do
> auto-conversion, converting literals and constants among other things to
> the correct size (though not performing alpha/numeric conversions).
> These size conversions are nice in testing, and also for using named
> constants.
>
> My question is whether there is a difference in the actual mechanism of
> the passing of the parameter.  I have to believe that with VALUE, a copy
> is made of the original variable and this copy is passed.  With CONST, I
> suppose it's possible that a pointer to the original data is passed, and
> it's up to the compiler to prevent modification.  That would be one
> reason why the compiler flags attempts to modify local parameters
> declared as CONST, but not those declared as VALUE.
>
> The reason I ask is that I'm trying to set up some programming
> standards.  Should I always pass parameters as CONST (except when they
> are truly going to be modified)?  Or are there cases (let's say the data
> is only 2 bytes long) where it might be more efficient to use VALUE,
> because only the actual data is being passed on the stack, not a
> pointer.
>
> Joe


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.