Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>passing and returning values</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Passing and returning values


Receiving Parameters in C

   The concept of C formal parameters disappears at this point.  All
   parameters may be accessed using the _par() functions. Therefore, all
   C functions accessed through the Extend System are declared with no
   formal parameters.


Returning Values From C

   The _ret() functions are used to return values back to Clipper.  Each
   function, by definition, can return only one value.  Which _ret()
   function you use depends on the data type being returned.


Sample C Function

   Once you compute the value you want to return, pass it to the
   appropriate _ret() function and it becomes the function return
   value.  It is still, however, necessary to execute a C return.
   _ret() functions do not pass control back to Clipper.


------------------------------ Structure Example ---------------------------

   Here is a shell of a typical Clipper user-defined function
   written in C:

      #include "extend.h"

      CLIPPER <function name>()     /* formal C parameters omitted */
      {
         declarations of local variables

         if (<parameters are valid>)
         {
            <code to execute>
         }
         else
         {
            <code to execute for undefined parameters>
         }
      }

-------------------------------- Actual example ----------------------------

   In Clipper:

      DECLARE arr[3]
      arr[1]   = "Deborah"
      arr[2]   = 456
      arr[3]   = CTOD("09/01/87")

      Arrfunc(arr)


   In C:

      #include "extend.h"   /* Declare Extend System */

      CLIPPER arrfunc()     /* specify CLIPPER */
                            /* macro to define function */
      {
         int x;

         for (x = 1; x  <= _parinfa(1, 0); ++x)
         {
            /* string variables */
            if (_parinfa(1, x) == CHARACTER)
            {
               cprintf("%s\n", _parc(1, x));
            }

            /* integer or floating point */
            if (_parinfa(1,x) == NUMERIC)
            {
               cprintf("%u\n", _parni(1, x));
            }
            else

               /* dates */
               if (_parinfa(1, x) == DATE)
               {
                  cprintf("%s\n", _pards(1, x));
               }
         }
         _ret();
      }


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson