Runtime interface functions

Your foreign subroutines can access the C string and data conversion functions, which are part of the Synergy runtime. You can only use these functions when you build a DLL or shared object with C routines (see Building a dynamic library with C routines).

You must pass the argument block pointer to runtime interface functions. This argument block pointer gets passed to your C routine. More than one argument block pointer can be active. For example, the following call is valid (from Synergy DBL):

xcall csub(%cfunc1, %cfunc2(%cfunc3))

Example using the Synergy DBL C interface

The example below illustrates the following:

;
; Calculate x to the yth power through the use of the system-supplied 
; subroutine pow() in the C routine pwrrti.c.
;

.define TTCHN        ,1
record
    input               ,a30
    xval                ,d10
    yval                ,d10
    result              ,d10
    rlen                ,d2
proc
    open(TTCHN, o, "tt:")
    repeat
      begin
        display(TTCHN, "x: ")
        reads(TTCHN, input) [eof=done]
        xval = input
        display(TTCHN, "y: ")
        reads(TTCHN, input) [eof=done]
        yval = input
        xcall power(result, xval, yval)
        input = result [left:rlen]
        writes(TTCHN, "(DBL) result: " + input(1:rlen))
      end
done,
end

subroutine sub1
    a_result            ,n
proc
    writes(TTCHN, "(C)   result: " + %string(a_result))
    return
endsubroutine


/* ---------------------------------------------------------------------
 *
 * Routine:      XCALL POWER(RESULT, IVAL, POWR)
 *                          
 * Description:  Calculate X to the nth power, display the result
 *               with a Synergy program, and return the result to
 *               the calling routine.
 *
 * Arguments:    RESULT, D; the result with size defined in the
 *               Synergy program limited to D10
 *                          
 *               IVAL,   D; Decimal value X
 *               POWR,   D; Power value n
 *
 * Requirements: UNIX   - link with -lm (math library)
 *
 * Notes:
 *
 *     To identify this routine, like .IDENT, declare a variable
 *     in the form: 
 *
 *        static char *var = "@(#)ident";
 *
 *     The runtime executable will contain the ident string and can
 *     be seen with the "what" command (e.g., what $DBLDIR/bin/dbr).
 *
 * ------------------------------------------------------------------ */
#include <math.h>
#include "xcall.h"
#define WROARG 6
static char *what = "@(#)POWER V2.0 (C-interface)";
extern double pow();

void
power(argblk)
DESCRIP **argblk;
{
   double num1, num2, result;
   SEGENTRY *segp;                              /* SEGENTRY & DESC are
   DESCRIP *exec_argblk[2];                     * defined in xcall.h */
   DESCRIP r_descr;

   if ((long)argblk[0] != 3)                    /* Expecting 3 args     */
      dblerror(WROARG);

   num1 = get_xarg_fval(argblk, 2);             /* Get the x and n      */
   num2 = get_xarg_fval(argblk, 3);             /*  arguments           */
   result = pow(num1, num2);                    /* Call pow function */
   put_xarg_fval(argblk, 1, result);            /* Load return val      */

   /* Set up a pointer to our return argument pairs to Synergy sub1 */
   exec_argblk[0] = (DESCRIP *)1;               /* Define one argument */
   exec_argblk[1] = get_xarg(argblk, 1, &r_descr);
   dbl_exec(get_seg_ptr("SUB1"), exec_argblk);   /* Call Synergy subroutine */
   return;
}