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



> Why is it that it is "better" this way?
> This way (using *OMIT) is how I do it, but why would it be better?

I think the reason she prefers the "*OMIT" method is that the compiler
knows the data type of the parameter, and therefore it can do better
validity checking.

Some people might argue that using pointers and %addr() is better, because
it more closely matches what you'd code in C.   However, I agree with
Barbara that the *OMIT method is probably better in RPG.

Just for the sake of clarifying what I mean, consider this code:


Here's the C code for reference:

void SomeProc(double *pTransExtdAmt, double *pTransTotalTx);

int main(int argc, char **argv) {
    double parm1;

    SomeProc(&parm1, NULL);
    return 0;
}

Note that the & (ampersand) before the parm1 in the call means "address
of" and is equivalent to the %addr() BIF in RPG.



Here's the "pointer" method in RPG:


     D SomeProc        PR                  ExtProc('SomeProc')
     D  pTransExtdAmt                  *   value
     D  pTransTotalTx                  *   value

     D parm1           s              8f
      /free

         SomeProc(%addr(parm1): *NULL);

      /end-free

You see, it looks almost the same as the C code. However, unlike C the
RPG compiler cannot tell that your pointer must be to an 8F.  The
programmer has to know that the data type he needs to pass is 8F, and the
compiler won't catch it if he does it wrong.

Now here's the *OMIT method:

     D SomeProc        PR                  ExtProc('SomeProc')
     D  pTransExtdAmt                 8F   options(*omit)
     D  pTransTotalTx                 8F   options(*omit)

     D parm1           s              8f

      /free

         SomeProc(parm1: *OMIT);

      /end-free


Here, the compiler knows about the 8F, and it's all that the compiler
will allow you to pass (aside from *OMIT.)  The code may not look as much
like the C code as the first example, but the validity checking is much
better -- and more like what the C compiler can do.


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.