× 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.



I use Value nearly all the time because I never know if the person using my
sub proc is going to be passing a literal or a variable.  I have used Const
once (don't remember why I chose it) so I don't know if that does or doesn't
have limitations if you try and pass literals.  

One thing to note if you are modifying your parameter variables - in the
event that a variable has the *NoPass or *Omit option and you modify one of
your input parms when actually it was omitted or not passed, you are then
writing over memory that you don't own.  So make sure you check %Parms or
*Null for *NoPass and *Omit, respectively, before you do anything to your
parameter variables.

HTH,
Aaron Bartell

-----Original Message-----
From: Joe Pluta [mailto:joepluta@xxxxxxxxxxxxxxxxx]
Sent: Thursday, August 07, 2003 3:04 PM
To: 'RPG programming on the AS400 / iSeries'
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

_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.

As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.