|
Joep, thats what i meant.
Some other
The keywords "value" and "const" are a bit confusing. In C (RPG these days
seems to be a bit of a strange mix of C and Pascal syntax and semantics)
all parameters are passed simply by value. The keyword "const" means that
you can not change it within the called function (of course you can still
change it through other references). If you have complex data (not just
simple datatypes) you can pass a pointer (which is passed by value like all
other datatypes). In C it's more common to work with pointers. This is
simple, elegant and predictable. You have only one way of passing
parameter, namely "by value". If you don't want to copy lots of data on the
stack you simply use &var (%addr(var) in RPG).
So i think i'm going to use "value" always (not with local procs only). And
if i need to pass lots of data (in principle always if i want to pass more
than just a basic type) i pass a pointer. The latter can be done with %addr
in the caller or by definining the parameter as "const". However if i use
"const" the behavior is not consistent. The compiler decides whether to
copy the variable or not (and i never want a copy just the const). This way
the semantics are the same as in C (except for the use of const), which
comes in handy if i ever want to convert the code to C. I don't see a real
downside in this approach, except that it makes more use of pointers with
which many RPG'ers are not comfortable. And that the semantics of "const"
is not the same as in C. So i'm still in doubt whether to use const (if i
want to pass a pointer) or use "value" with %addr. The latter case is a bit
convoluted but we're used to that in RPG (need at least 6 specs to start a
free form procedure impl without even one parameter). But i can't use the
const semantics of keyword "const" (like in C) because it mostly also means
"copy".
On Wed, May 1, 2013 at 1:39 AM, Sam_L <lennon_s_j@xxxxxxxxxxx> wrote:
Correct, but if you inadvertently forget to define a local variable on aput
d-spec and a global one exists the procedure will quietly and quite
happily use the global one, possibly with disastrous or random effects.
Sam
On 4/30/2013 6:39 AM, paultherrien@xxxxxxxxxxxxxxxxxx wrote:
I may not understand what you are saying, but it is my understandingthat if
you use a d-spec in your procedure to define a variable then thevariable is
local to the procedure.rpg400-l-bounces@xxxxxxxxxxxx]
Paul
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:
On Behalf Of Sam_L
Sent: Monday, April 29, 2013 5:31 PM
To: RPG programming on the IBM i (AS/400 and iSeries)
Subject: Re: Procedure PR/PI question
I would like to have an option that says "All the variables I define in
this procedure are local unless I specify otherwise". I know, if I
alwaysit in a separate source file I get the same effect, but this isn't
--practical or politically acceptable in some shops.
Sam
--
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.
As an Amazon Associate we earn from qualifying purchases.
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.