home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / lisp / 2250 < prev    next >
Encoding:
Text File  |  1992-08-19  |  2.0 KB  |  80 lines

  1. 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
  2. From: harry@issun1.kfk.de (Harald Kucharek)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Calling C function from LCL
  5. Message-ID: <Bt8G1E.229@iai.kfk.de>
  6. Date: 19 Aug 92 13:27:13 GMT
  7. Sender: usenet@iai.kfk.de
  8. Reply-To: harry@issun1.kfk.de
  9. Organization: Kernforschungszentrum Karlsruhe
  10. Lines: 67
  11. Nntp-Posting-Host: issun1
  12.  
  13. I have the following little C program:
  14.  
  15. #include <stdio.h>
  16. int 
  17. ca(my_array)
  18.     int             my_array[2][2];
  19.  
  20. {
  21.     int             i, j;
  22.     int             result = 0;
  23.     for (i = 0; i < 2; ++i) {
  24.         for (j = 0; j < 2; ++j) {
  25.             printf("%d\n", my_array[i][j]);
  26.             result += my_array[i][j];
  27.         }
  28.     } return (result);
  29. }
  30.  
  31. which I want to call from LISP (I am using Lucid Common Lisp 4.0.1 on a SPARCstation330)
  32. I define:
  33.  
  34. (def-foreign-function (run-ca (:return-type :signed-32bit)
  35.             (:name "_ca")
  36.             (:language :c))
  37.     (my_array (:array :signed-32bit (4))))
  38.  
  39. (load-foreign-files "/home/harry/C/ca.o")
  40.  
  41. which gives the output:
  42. ;;; Loading foreign object file "C/ca.o"
  43. ;;; Reading library file "/lib/libc.a"
  44. ;;; Reading library file "/lib/libm.a"
  45. ;;; Warning: The following foreign symbols are undefined: (__DYNAMIC)
  46. NIL
  47.  
  48.  
  49. (setq a (make-array '(2 2) :element-type 'integer))
  50.  
  51. (loop for i from 0 to 1 do
  52.     (loop for j from 0 to 1 do
  53.         (setf (aref a i j) (+ i j))))
  54.  
  55. (run-ca a)
  56.  
  57. which outputs:
  58.  
  59. 0
  60. 4
  61. 4
  62. 8
  63. 16
  64.  
  65. Questions:
  66.  
  67. 1) What is this missing symbol __DYNAMIC
  68. 2) The contents of the array are all multiplied by 4. Has this something
  69.    to do with the type of the lisp object? I always thought, it is coded in the high order
  70.    bits of the data.
  71. 3) What is wrong in my declaration of the foreign function, that make all these things happen?
  72.  
  73. Thanks for any suggestions.
  74.  
  75. Harald
  76.  
  77.     Harald Kucharek ($B>.?M(J), Nuclear Research Center Karlsruhe, IDT
  78.         7514 Eggenstein-Leopoldshafen, Germany
  79.          Internet: harry@issun1.kfk.de Phone: +49 7247 825706 
  80.