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



Steve,

I am certainly not afraid of using pointers.  I've used them to do some
really great stuff, but honestly, most of the programmers I work with would
be hard pressed to understand the code.  They're not bad programmers,
uninterested or unmotivated, just unfamilliar with the concepts involved.
So, if I use pointers, I leave them in a service program where the
programmers won't see it.  They don't need to know the mechanics in order to
use a procedure.

All that aside, can you tell me WHAT would be better about CL if it
supported pointers.
How would you enter a pointer value into a command entry field?  Why?!??

Eric DeLong
Sally Beauty Company
MIS-Project Manager (BSG)
940-898-7863 or ext. 1863


-----Original Message-----
From: Steve Richter [mailto:srichter@autocoder.com]
Sent: Wednesday, November 20, 2002 1:44 PM
To: rpg400-l@midrange.com
Subject: RE: CL pgm and pointer variables


Eric,

Pointers are nothing to be afraid of. ( regardless of what Hans says ) And
why not use them when they allow your code to be more direct, easier to
read, more to the "point"?

There are problems, maybe better said as "potential sources of errors", when
using pointers.  The first PSE is that pointers are typeless, that is the
compiler does not know whether the pointer points to a packed decimal, a
character string or data structure. A good start in dealing with this
problem is to allow a pointer to be declared with a type attribute:
  d pName       s           *    Like( OrdHdr.CustName )
  d pOrdHdr     s           *    likeds( OrdHdr )

An additional way to reduce type mixup errors is to permit data pointers to
be used in rpg.  Data pointers were built into the original s/38 by some
genius who was surely banished from Rochester long ago. A data pointer
contains both a pointer to something and also the attributes of the
something.  This elimiates the type mixup and makes for even cleaner code.
 d Name        s          30a
 d AnotherName s          30a
 d Amount      s           7p 2
 d dpSomething s            *     dataptr
   /free
     dpSomething = %AddrAndAttr( Name ) ;
     AnotherName = dpSomething ; // copies Name to AnotherName
   /end-free

The 2nd source of error is not with the pointer itself, but the requirement
to free the memory that has been allocated as the program runs. That is you
must Dealloc what has been %alloc'd.

The current RPG ILE is wide open for this kind of error.  To deal with it
you either go the java route and handle all alloc and dealloc internally. Or
go the C++ route and implement real good scoping with constructor and
destructor code that runs automatically on scope entry and exit (
procedure/program entry and exit ).

Steve Richter


_______________________________________________
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-Ups:

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.