|
From: Sri <w2...@ya...> - 2010-01-20 11:36:39
|
Hi,
I am using SWIG to generate perl wrappers for a fairly large, existing C API used at work. In the swig interface file I just include a "master" headerfile that includes all the other required files. However, I'm getting "Syntax error in input(3)" error and cant figure out what I'm doing wrong. The original code compiles fine with many C compilers.
The problem seems to be due to declaring an arrays' size via a macro #defined earlier (int nVals[NUM_VALS]; line in my example below)
I've been able to reproduce the problem with a fairly simple example. I hope someone knows what I'm doing wrong or how to workaround this.
Example demonstrating the problem uses : test.i, a.h, b.h.
command : swig -includeall -perl5 test.i
Result: b.h:13: Error: Syntax error in input(3).
Same functionality, rewritten as test2.i doesnot cause error
command: swig -perl5 test2.i
Using swig 1.3.40.
---test.i ----
(this is essentially, how my real .i file looks..just a "master" .h)
%module myTest
%{
#include "a.h"
%}
%include "a.h"
----a.h----
#include "b.h"
----b.h----
enum
{
FIRST_VAL,
SECONDVAL,
MAX_VAL
};
#define NUM_VALS ((MAX_VAL/2) + ((MAX_VAL % 2) ? 1: 0))
typedef struct
{
int aVal;
int nVals[NUM_VALS];
} tMyStruct;
void MyFunc (tMyStruct avar);
--- test2.i ---
%module myTest
%{
enum
{
FIRST_VAL,
SECONDVAL,
MAX_VAL
};
#define NUM_VALS ((MAX_VAL/2) + ((MAX_VAL % 2) ? 1: 0))
typedef struct
{
int aVal;
int nVals[NUM_VALS];
} tMyStruct;
%}
void MyFunc (tMyStruct avar);
--- swig preprocessor (-E) output ---
error case, the array declaration expands to this output:
int nVals[((MAX_VAL/2) + ((MAX_VAL % 2) ? 1: 0))];
In working case, the array declaration is unchanged in the output.
int nVals[NUM_VALS];
|