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



Kevin,

>whoa! stop! put on the brakes! 
>
>Someone 'splain this to me! I am all ears!

Every system includes the C runtime library, even if they don't have
the C compiler.  This lets vendors ship code compiled with C.  Prior
to RPG IV, this was of little benefit to RPG programmers.

With RPG IV, it is possible to prototype calls to the C functions and
call them from your RPG programs.  But as Bob points out, it helps if
you have some idea of how C works.

Starting with V3R7, IBM added support for Options( *String ) on the
D-spec.  This automagically provides a null-terminated string and was
specifically added to aid in calling C functions.  V3R7 also added
support for floating-point fields, which are needed for calling many
of the C library math functions.  

>From V3R7 on, using C functions is no big deal.  Prior to that, you
can't use things with FP fields, and you had to add the x'00'
terminator yourself.  So rather than prototyping and calling the C
function directly, you would code a subprocedure wrapped around the C
function to handle null termination, etc.  Options( *String ) is much
easier. :)

At any rate, your softcopy CD will have the C Library Reference, or
you can look it up on the Web.  But basically you just need to add a
prototype into your RPG source and compile with Bnddir( 'QC2LE' ) then
call the function from your code.

You can setup a /COPY member for the prototypes of the C function(s)
you commonly use, and include that in your source rather the prototype
itself.

Here is a sample program from Barbara Morris of the IBM Toronto Lab,
which should give you some ideas:

     H bnddir('QC2LE') 
     D atof            pr             8f   extproc('atof')
     D   ptr_to_char                   *   value options(*string)

     D char            s             10a   inz('-123.45')
     D num             s              7p 3
     D msg             s             52a

     C                   eval      num = atof(%trimr(char)) 
     C                   eval      msg = char + '=' + %editc(num:'N')
     C     msg           dsply                                       
     C                   return                                       

Barbara Morris, IBM Toronto Lab, RPG Compiler Development 
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


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.