Initial C module file and simple example added.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10501 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8b42082f88
commit
338347feb0
9 changed files with 220 additions and 0 deletions
12
Examples/c/simple/Makefile
Normal file
12
Examples/c/simple/Makefile
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
EXEC = main.c
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' EXEC='$(EXEC)' c
|
||||
|
||||
|
||||
18
Examples/c/simple/example.c
Normal file
18
Examples/c/simple/example.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* File : example.c */
|
||||
|
||||
/* A global variable */
|
||||
/* double Foo = 3.0; */
|
||||
|
||||
/* Compute the greatest common divisor of positive integers */
|
||||
int gcd(int x, int y) {
|
||||
int g;
|
||||
g = y;
|
||||
while (x > 0) {
|
||||
g = x;
|
||||
x = y % x;
|
||||
y = g;
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
|
||||
6
Examples/c/simple/example.i
Normal file
6
Examples/c/simple/example.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%inline %{
|
||||
extern int gcd(int x, int y);
|
||||
%}
|
||||
8
Examples/c/simple/main.c
Normal file
8
Examples/c/simple/main.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int a = 35;
|
||||
int b = 15;
|
||||
printf("GCD(%d, %d)=%d", a, b, gcd(a, b));
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue