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



Charles,

Maybe you missed something in my post, but i meant to use the * datatype
with "value". Thats why i used %addr in my example. I know the difference
between "value", "const" and no keyword at all.




On Wed, May 1, 2013 at 2:38 PM, Charles Wilt <charles.wilt@xxxxxxxxx> wrote:

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.

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
a
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 understanding
that if
you use a d-spec in your procedure to define a variable then the
variable is
local to the procedure.


Paul


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:
rpg400-l-bounces@xxxxxxxxxxxx]
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
put
it in a separate source file I get the same effect, but this isn't
always
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.


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

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.