link cfunc
April 26, 2002; Kostas Oikonomou
This file is in the public domain.
This file provides three procedures for translating homogeneous lists of integers, reals, or strings to C arrays: IListVal(d) returns an array of C ints. RListVal(d) returns an array of C doubles. SListVal(d) returns an array of C char pointers (char *). ____________________________________________________________ Here is an example of using this interface: 1. gcc -I/opt/icon/ipl/cfuncs -shared -fPIC -o llib.so l.c where "l.c" is the C fragment below. #include "ilists.c" int example(int argc, descriptor argv[]) { int *ia; double *ra; char *(*sa); int n; int i; ArgList(1); n = ListLen(argv[1]); ia = IListVal(argv[1]); for (i=0; i<n; i++) printf("%i ", ia[i]); printf("\n"); ArgList(2); n = ListLen(argv[2]); ra = RListVal(argv[2]); for (i=0; i<n; i++) printf("%f ", ra[i]); printf("\n"); ArgList(3); n = ListLen(argv[3]); printf("n = %i\n", n); sa = SListVal(argv[3]); for (i=0; i<n; i++) printf("%s ", sa[i]); printf("\n"); Return; } 2. The Icon program that loads "example" from the library llib.so: procedure main() local e, L1, L2, L3 e := loadfunc("./llib.so", "example") L1 := [] every i := 1 to 5 do put(L1,10*i) L3 := ["abcd","/a/b/c","%&*()","","|"] e(L1,[1.1,2.2,-3.3,5.5555],L3) end