By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,275 Members | 1,745 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,275 IT Pros & Developers. It's quick & easy.

Structure C and transform it to Python using Swig

P: 16
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
Share this Question
Share on Google+
1 Reply


varuns
P: 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.