home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gofer230.zip / Progs / Gofer / Demos / CallingC / Readme < prev   
Text File  |  1994-06-23  |  1KB  |  43 lines

  1. Here is a simple example using the external function mechanism.
  2. It involves the following short Gofer and C programs:
  3.  
  4. (gix1.gs):    primitive howdy "sayHello" :: Int -> IO ()
  5.  
  6.               main = howdy (length (filter even [1..5]))
  7.  
  8.  
  9. (cix1.c):     #include <stdio.h>
  10.               #include "gofc.h"
  11.  
  12.               Void sayHello(i)
  13.               Int i; {
  14.                   while (i-- > 0)
  15.                       printf("hello, world\n");
  16.               }
  17.  
  18. First, we compile gix1.gs to get a C program gix1.c:
  19.  
  20.     machine% gofc gix1.gs
  21.     Gofer->C Version 1.02 (2.30)  Copyright (c) Mark P Jones 1992-1994
  22.  
  23.     Reading script file "/usr/local/lib/Gofer/standard.prelude":
  24.     Reading script file "gix1.gs":
  25.                    
  26.     Writing C output file "gix1.c":
  27.     [Leaving Gofer->C]
  28.  
  29. Now we compile the C programs, and link them into a single executable
  30. file, ix1:
  31.  
  32.  
  33.     machine% cc -O -o ix1 gix1.c cix1.c runtime.o
  34.  
  35. Finally, we get to run the program:
  36.  
  37.     machine% ix1
  38.     hello, world
  39.     hello, world
  40.  
  41. Wow!
  42.  
  43.