469,575 Members | 1,662 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Structure C and transform it to Python using Swig

Hello
I am trying to convert and manage a simple structure C ,to Python by using SWIG. The code is the following :
/* example.c*/
double sum(Vector c)
{
return c.x+c.y+c.z;
}
/*header.h*/
struct Vector{
double x,y,z;
}
/*interface_file.i*/
%module interface
%{
#include "structure.h"
%}
#include "structure.h"

I execute the following commands:
swig -python interface.i
gcc -c example.c interface_file_wrap.c -I/usr/include/python2.5
and after that an error appears:
example.c:3: error: expected ‘)’ before ‘c’
What is the solution?
Aug 10 '07 #1
1 2321
varuns
39
Hello
I am trying to convert and manage a simple structure C ,to Python by using SWIG. The code is the following :
/* example.c*/
double sum(Vector c)
{
return c.x+c.y+c.z;
}
i think "Vector c" is a local variable, so make it as "Vector *c" and function definition as
Expand|Select|Wrap|Line Numbers
  1. double sum(Vector *c)
  2. {
  3. return (c->x+c->y+c->z);
  4. }
and call the function as

Vector a;
sum(&a);

bye
Aug 10 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Gary | last post: by
reply views Thread by Helmut Zeisel | last post: by
13 posts views Thread by Roy Smith | last post: by
1 post views Thread by Arthur Chereau | last post: by
6 posts views Thread by matey | last post: by
reply views Thread by Basha J P M | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.