Global variable and function handling from C to C.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10526 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Maciej Drwal 2008-06-16 15:27:36 +00:00
commit a5b8db8296
6 changed files with 106 additions and 41 deletions

View file

@ -3,10 +3,12 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
EXEC = main.c
MAIN = main.c
all::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' EXEC='$(EXEC)' c
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MAIN='$(MAIN)' c
clean:
rm *.o

View file

@ -3,6 +3,14 @@
/* A global variable */
double Foo = 3.0;
double *Foo_ptr = &Foo;
char *my_str = "hello, world!";
char *array_of_strs[] = { "one", "two" };
char *get_str(int i) {
return array_of_strs[i];
}
/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
int g;

View file

@ -3,6 +3,10 @@
%inline %{
extern double Foo;
extern double *Foo_ptr;
extern char *my_str;
extern char **array_of_strs;
extern char *get_str(int i);
extern int gcd(int x, int y);
%}

View file

@ -6,6 +6,9 @@ int main(int argc, char **argv) {
int a = 35;
int b = 15;
printf("Foo is %f\n", Foo);
printf("Foo by ptr is \%f (%d)\n", *Foo_ptr, (int) Foo_ptr);
printf("my_str is: %s\n", my_str);
printf("array_of_strs contains %s and %s\n", get_str(0), get_str(1));
printf("GCD(%d, %d)=%d\n", a, b, gcd(a, b));
return 0;
}