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





> -----Original Message-----
> From: Hatzenbeler, Tim [mailto:thatzenbeler@clinitech.net]
> Sent: Wednesday, August 18, 1999 8:52 AM
> To: 'RPG400-L@midrange.com'
> Subject: C Functions..
> 
> 
> I was wondering if I could talk any one into posting a few 
> examples, on how
> the prototyped and compiled some of the C functions into their RPG
> applications...
> 
> I was interested in a few of the Math and String Conversion 
> Functions, It
> really doesn't matter which ones, I was just looking for some 
> in general, so
> I can see the pattern, so I can write my own prototypes.
> 
> Thanks, Tim
> 


Here's a prototype for the C binary search function shamelessly cribbed from
an article in RPG Source from last year.  I use it a lot--it's faster than
the RPG subroutine I ported from my data structures textbook.
Note that the return value is a pointer.  If it doesn't find the lookup
argument, it returns NULL.  Compfunc is a procdure pointer to a procedure
that does the actual comparison, in this case compvis() which returns an
integer describing the result of the comparison.  This makes the binary
search type independent.  You do have to write a comparison procedure for
every data type you need to compare.
 

0032.00 D* ####### c library binary search
####################################    
0033.00 Dfindit           pr              *   extproc('bsearch')

0034.00 Dlookfor                          *   value

0035.00 Ddatastart                        *   value

0036.00 Delements                       10u 0 value

0037.00 Dsize                           10u 0 value

0038.00 Dcompfunc                         *   procptr  value  
0039.00 D* ######## nbritmrec comparison function
############################ 
0040.00 Dcompvis          pr             9b 0

0041.00 Dlookfor                          *   value

0042.00 Darrelt                           *   value

0043.00 D


Pcompvis          b                                               
D                 pi             9b 0                             
Dlookfor                          *   value                       
Darreltptr                        *   value                       
Dkey              s                   like(dvis) based(lookfor)   
Darrelt           s                   like(dvis) based(arreltptr) 
C                   select                                        
C                   when      key < arrelt                        
C                   return    -1                                  
C                   when      key > arrelt                        
C                   return    1                                   
C                   when      key = arrelt                        
C                   return    0                                   
C                   endsl                                         
Pcompvis          e                                               
                                                                  
If you're interested in higher math functions, check out the ILE APIs.
They're very easy to prototype and include in your programs, especially
since the softcopy manual has tables that show the data types of the
parameters in all the AS/400 languages. 

When you use C functions, you have to remember to specify binding directory
QC2LE when you compile and link.
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-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 ...


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.