Structure C and transform it to Python using Swig

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nimitsis
    New Member
    • Aug 2007
    • 16

    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?
  • varuns
    New Member
    • Jun 2007
    • 39

    #2
    Originally posted by nimitsis
    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
    Code:
    double sum(Vector *c)
    {
    return (c->x+c->y+c->z);
    }
    and call the function as

    Vector a;
    sum(&a);

    bye
    Last edited by varuns; Aug 10 '07, 11:03 AM. Reason: Enclosing return value with ()

    Comment

    Working...