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



This is a multipart message in MIME format.
--
[ Picked text/plain from multipart/alternative ]
Wouldn't an easy solution to divide-by-zero errors be to just not use
division?

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




"Booth Martin" <Booth@MartinVT.com>
Sent by: rpg400-l-admin@midrange.com
11/20/2002 03:12 PM
Please respond to rpg400-l

        To:     <rpg400-l@midrange.com>
        cc:
        Fax to:
        Subject:        RE: CL pgm and pointer variables


--
--
[ Picked text/plain from multipart/alternative ]


Wouldn't an even easier solution to these inherent problems with pointers
be
to just not use pointers?


---------------------------------------------------------
Booth Martin   http://www.MartinVT.com
Booth@MartinVT.com
---------------------------------------------------------

-------Original Message-------

From: rpg400-l@midrange.com
Date: Wednesday, November 20, 2002 02:48:27 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
--
[ IMSTP.gif of type image/gif deleted ]
--

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