× 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 think you are being pointer phobic.  I feel for you - I used to be too.
But I've seen the light.

Let's say that a Luddite wanted to avoid pointers.  But they overlayed a 4
element array over a data structure that was only 3 elements big - as in
your example.  Wouldn't they still be suffering a problem?  So this problem
is not really pointer specific.

I've heard this before "You are also assuming that consecutive fields in a
file are stored in consecutive memory location which is not always the
case."  But I've seen no examples.


Rob Berendt
--
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety."
Benjamin Franklin



                    "Denis
                    Robitaille"             To:     <rpg400-l@midrange.com>
                    <DRobitaille@casc       cc:
                    ades.com>               Fax to:
                    Sent by:                Subject:     Re: Basing a field on 
an unreferenced field(s) doesn't work
                    rpg400-l-admin@mi
                    drange.com


                    01/11/2002 10:56
                    AM
                    Please respond to
                    rpg400-l






This is the thing with pointers. It can introduce bugs when you dont expect
it. For example, let say that all 3 fields were reference. You could still
be in trouble if you specify a dim of 4 for your array. What will be in the
fourth elements? You are also assuming that consecutive fields in a file
are stored in consecutive memory location which is not always the case.

Denis Robitaille
Directeur services techniques
Cascades Inc
819 363 5187
fax 819 363 5177


>>> rob@dekko.com 01/11/02 09:40am >>>

I have this simple RPGLE program:
     fARRAYF    IF   E           K DISK

     d MyVar1          s                   like(keyfld)
     d MyVar2          s                   like(Ary1)
     d MyVar3          s                   like(Ary2)
     d MyVar4          s                   like(Ary3)

      /FREE
       SETLL *LOVAL ARRAYF;
       read arrayf;
       DOW %STATUS(ARRAYF)=0;
        MyVar1=KeyFld;
        MyVar2=Ary1;
        MyVar3=Ary2;
        // MyVar4=Ary3;
        read arrayF;
       EndDo;
       *inlr=*on;
      /END-FREE

I compiled it with *list for debugging.  When I open it in the Code
debugger it will pull in the following I specs:
        73=IARYREC
        74=I                             A    1   10  KEYFLD
        75=I                             P   11   13 0ARY1
        76=I                             P   14   16 0ARY2
        77=I                             P   17   19 0ARY3
Four of the five lines will be blue.  The Ary3 line will be black because
it is unreferenced.  If I display any of the other fields after the read
they will have a value - Ary3 will not.  And if you did not disable the
debugging of I/O it will stop on lines 73-76 but not 77.  At this point you
may be wondering why should I care?  I am getting there.  If I modify the
program to look like:
     fARRAYF    IF   E           K DISK

     d MyArray         s                   like(Ary1) dim(3)
     d                                     based(pMyArray)
     d pMyArray        s               *   inz(%addr(Ary1))
      /FREE
       SETLL *LOVAL ARRAYF;
       read arrayf;
       DOW %STATUS(ARRAYF)=0;
        MyArray(1)=MyArray(1);
        MyArray(2)=MyArray(2);
        MyArray(3)=MyArray(3);
        read arrayF;
       EndDo;
       *inlr=*on;
      /END-FREE
Ary1 and MyArray(1) will have a value because Ary1 is a referenced field.
Ary2, Ary3 and MyArray(2-3) will not have values because Ary2 and Ary3 are
unreferenced fields.

Now, in my opinion Ary2 and Ary3 are NOT unreferenced fields because they
are being used in an array.

Granted, setting a variable equal to itself won't normally be done - I just
did that for debugging purposes.

Rob Berendt
--
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety."
Benjamin Franklin

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


_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l
or email: RPG400-L-request@midrange.com
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.