472,127 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

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 2413
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.