|
Think you're a bit confused...
RPG passes pointers only unless you specify VALUE. Originally pointers
where all that were supported. CONST simply tells the compiler to prevent
the data being pointed to from being changed.
Here's another way to look at it
d somevar s 1000a
d myproc1
d parm1 1000a
d myproc2
d parm1 * value
myproc1(samevar);
myproc2(%addr(somevar));
What's passed for myproc1 and myproc2 is EXACTLY the same, the address of
somevar.
In fact, you could use either prototype for the same called
procedure/program.
Charles
On Wed, May 1, 2013 at 7:14 AM, whatt sson <whattssonn@xxxxxxxxx> wrote:
Joep, thats what i meant.days
Some other
The keywords "value" and "const" are a bit confusing. In C (RPG these
seems to be a bit of a strange mix of C and Pascal syntax and semantics)all
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
other datatypes). In C it's more common to work with pointers. This isthe
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
stack you simply use &var (%addr(var) in RPG).And
So i think i'm going to use "value" always (not with local procs only).
if i need to pass lots of data (in principle always if i want to passmore
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 useway
"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
the semantics are the same as in C (except for the use of const), whichreal
comes in handy if i ever want to convert the code to C. I don't see a
downside in this approach, except that it makes more use of pointers withbit
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
convoluted but we're used to that in RPG (need at least 6 specs to starta
free form procedure impl without even one parameter). But i can't use themeans
const semantics of keyword "const" (like in C) because it mostly also
"copy".a
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
ind-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
(RPG400-L)putthis 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)
--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.
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.