home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!lll-winken!elroy.jpl.nasa.gov!sdd.hp.com!mips!darwin.sura.net!Sirius.dfn.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!unido!idtuva!issun1!harry
- From: harry@issun1.kfk.de (Harald Kucharek)
- Newsgroups: comp.lang.lisp
- Subject: Calling C function from LCL
- Message-ID: <Bt8G1E.229@iai.kfk.de>
- Date: 19 Aug 92 13:27:13 GMT
- Sender: usenet@iai.kfk.de
- Reply-To: harry@issun1.kfk.de
- Organization: Kernforschungszentrum Karlsruhe
- Lines: 67
- Nntp-Posting-Host: issun1
-
- I have the following little C program:
-
- #include <stdio.h>
- int
- ca(my_array)
- int my_array[2][2];
-
- {
- int i, j;
- int result = 0;
- for (i = 0; i < 2; ++i) {
- for (j = 0; j < 2; ++j) {
- printf("%d\n", my_array[i][j]);
- result += my_array[i][j];
- }
- } return (result);
- }
-
- which I want to call from LISP (I am using Lucid Common Lisp 4.0.1 on a SPARCstation330)
- I define:
-
- (def-foreign-function (run-ca (:return-type :signed-32bit)
- (:name "_ca")
- (:language :c))
- (my_array (:array :signed-32bit (4))))
-
- (load-foreign-files "/home/harry/C/ca.o")
-
- which gives the output:
- ;;; Loading foreign object file "C/ca.o"
- ;;; Reading library file "/lib/libc.a"
- ;;; Reading library file "/lib/libm.a"
- ;;; Warning: The following foreign symbols are undefined: (__DYNAMIC)
- NIL
-
-
- (setq a (make-array '(2 2) :element-type 'integer))
-
- (loop for i from 0 to 1 do
- (loop for j from 0 to 1 do
- (setf (aref a i j) (+ i j))))
-
- (run-ca a)
-
- which outputs:
-
- 0
- 4
- 4
- 8
- 16
-
- Questions:
-
- 1) What is this missing symbol __DYNAMIC
- 2) The contents of the array are all multiplied by 4. Has this something
- to do with the type of the lisp object? I always thought, it is coded in the high order
- bits of the data.
- 3) What is wrong in my declaration of the foreign function, that make all these things happen?
-
- Thanks for any suggestions.
-
- Harald
-
- Harald Kucharek ($B>.?M(J), Nuclear Research Center Karlsruhe, IDT
- 7514 Eggenstein-Leopoldshafen, Germany
- Internet: harry@issun1.kfk.de Phone: +49 7247 825706
-