Example 4

/***
* Template.c
*
* By: Scott McIntosh, Nantucket Corp.
*
* This function contains an example of how to write C code that can be
* interface to C or to Clipper.
*
* Note: this is only an example with pseudo-code. It will not actually
* compile.
*/

#include <whatever.h>

#define IS_CLIPPER // comment out this directive for stand-alone EXE

#ifdef IS_CLIPPER

#include "extend.h"
#define GRAB_MEM(bytes) _xalloc(bytes)
#define FREE_MEM(ptr) _xfree(ptr)

#else

#include <malloc.h>
#define GRAB_MEM(bytes) malloc(bytes)
#define FREE_MEM(ptr) free(ptr)

#endif

char * SomeFunc( int parm1, double parm2 ) // note: standard C function

char * ret;

// generic memory allocation usage example
if ((ret = GRAB_MEM(100)) == NULL)
; // sorry - no memory

else
; // presumably we would do something with all the parameters and
// store something in the return variable

return (ret);

}


#ifdef IS_CLIPPER

CLIPPER ClipFunc(void)
{
int arg1;
double arg2;

arg1 = _parni(1);
arg2 = _parnd(2);

// normally we would do some parameter checking here

_retc( SomeFunc( arg1, arg2 ) );

}

#else

#include <stdio.h>
#include <stdlib.h>

void main( int argc, char * argv[] )
{

int arg1;
double arg2;

arg1 = atoi( argv[1] ); // get the command line parameters
arg2 = atof( argv[2] );

printf( "The result is %s", SomeFunc( arg1, arg2 ) );


}

/* EOF: Example 4 */