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



As I have said many times, VALUE means the compiler says I guarantee that
variable in the calling program will not be changed and it does that by
making a copy and pass a pointer to it. In the procedure you can do
anything you want with that parameter including changing it and it will
have no impact on the variable in the caller.

CONST means I will try to keep you from changing it but there are plenty of
ways to change the variable inside the procedure and have the calling
variable to be changed. These include passing as a parameter to a program
inside the procedure, getting a pointer to it, putting in a data structure.
The compiler may try to prevent you from changing but it is easy enough to
change which could result in some really nasty bugs.

That is why I always use a VALUE unless I passing something really big and
lately I have using Option(*String) to pass long variable strings. It only
passes the actual length of a variable instead of it's declared length. Now
if we could get IBM to put the actual length into the Operational
Descriptor we would be set. .


On Mon, Apr 29, 2013 at 11:05 AM, Rory Hewitt <rory.hewitt@xxxxxxxxx> wrote:

whatt,

If you have a variable passed as a Const parameter that is also defined as
a global variable, the yes, you can get problems. But that has nothing to
do with the Const parameter, and everything to do with the module design.
All you need to do is rename the parameter (and how it's defined in the
procedure) and the compiler will use a new variable.

Rory


On Mon, Apr 29, 2013 at 1:59 AM, whatt sson <whattssonn@xxxxxxxxx> wrote:

Hi Barbara,

I usually also default to const.
But i'm not sure if this is always a good idea because sometimes you get
aliasing problems.
And i would rather have a program that is correct instead of a program
that
performs a little better but where you have a chance that some nasty bug
gets introduced.

Now i default to value instead of const when i'm coding a local
procedure.
For example, when i call a local procedure with a const parameter and
pass
a variable that is globally defined within the same module chances are
that
the parameter value "suddenly" is changed while executing that procedure.
For example when this procedure calls another local procedure doing
things
with this global variable. This happens more often that you (i) think,
for
example if the variable is a (record) datastructure. I pass it to a local
procedure (by ref) which reads a file a fills the datastructure, etc.
This
pattern is quite common (passing record structures) but in this case you
really have to be careful.

However, if the procedure is in another module chances are much less that
calling this procedure has these kinds of side effects (and we don't want
side effects) happen because the other module is in another name space.

So i've chosen to always default to value for local procedures (i.e. they
are by defnition only called from within the same module), and const for
the other procedue (which can also be called locally of course).

But i'm still a bit in doubt. Always defaulting to value will make the
code
more robust and easier to reason about. And defaulting to const is a kind
of premature optimization. And in cases where you have to pass large
chunks
of data (>1k ?) it could be a good idea to use const for performance. But
in our environment which is mainly I/O bound this shouldn't be a problem
most of the time.


On Sat, Apr 27, 2013 at 6:14 AM, Barbara Morris <bmorris@xxxxxxxxxx>
wrote:

On 4/25/2013 8:19 PM, Alan Campin wrote:

If creating a procedure.

d pWriteScaleLog...
d pr
d PR_InScaleMessage...
d 128a Value


I would normally use CONST rather than VALUE for the string parameters
of a procedure. The difference in performance between CONST and VALUE
can be noticeable, especially for large varying length parameters where
the actual length is small. Maybe not particularly noticeable for 128,
but I still think it's a good practice to default to CONST rather than
VALUE for strings.

Unless the called procedure needs to change the parameter for its own
use, and even then, it might still perform much better to pass the
parameter by CONST, and make a local copy inside the procedure.

--
Barbara
--
This is the RPG programming on the IBM i (AS/400 and 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.


--
This is the RPG programming on the IBM i (AS/400 and 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.




--
Rory Hewitt

http://www.linkedin.com/in/roryhewitt
--
This is the RPG programming on the IBM i (AS/400 and 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-Ups:
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.