Re: Passing arrays between 4GL and C
Posted in 1994
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Jonathan Leffler (johnl@informix.com) wrote: [ deletia ] : You cannot pass arrays between functions in I4GL. Period. : You cannot pass arrays into C functions called from I4GL. : You cannot pass arrays from C functions to the calling I4GL code. [ deletia ] OK, so you can't. But if you _really_ have to anyway: Try declaring a static array in your C function, and passing the values in with successive calls in a loop. Get the values back one at a time in a loop as well. Probably need a pair of access functions with a shared (static) array, and a processing function to do it. This is an example only; not bulletproof, not tested, not even proofread, so flames > /dev/null. /* C funcs to process arrays */ static int arr[SIZE]; /* private to C funcs put() and get() */ static int index; #define NEXT (-1) /* put(a) * Insert a into arr[] * If a == NULL then reinitialize arr[] to start over. */ put(int a) { if (!a) { index = 0; memset(arr, 0, sizeof(arr)); index = 0; } else arr[index] = a; return 0; } /* get(a) * If a == NEXT then return next arr[] and increment index * else return arr[a] and reset index. */ get(int a) { if (a == NEXT) return a[index++]; else return arr[index = a]; } /* process() * Do stuff with arr[]. arr[] is NULL-terminated. */ process() { /* ... */ } Regards, Craig Ludington