Passing Incompatible Structs Between C and XC
Posted: Wed Jul 19, 2017 4:10 am
I would like to be able to pass a struct by reference from XC, through some C function calls, back to an XC function, where it would be usable as if it had never been passed via C. The particular struct I would like to pass is shown here.
In XC land, this struct can be passed by reference to any XC function I want, and I can operate on chanend *movable c as one would expect to be able to. The problem enters when I try to pass a MyStruct reference to a C function. Usually xccompat.h helps with this, where I can use REFERENCE_PARAM(MyStruct, myStructRef) in the function headers to convert the reference to a pointer for the C function calls. In this instance, I also need to remove the "movable" keyword for the C side of the build by doing "#ifndef (__XC__) #define movable ". This removes the movable keyword when built for C, but in the process changes the definition of MyStruct for C versus XC, causing a compilation error.
c_functions.c: Error: Type of symbol first_c_function has mismatch with previous definition:
c_functions.c: Error: found: void first_c_function(struct *)
../main.xc: Error: previous: void first_c_function(struct &)
../xc_functions.xc: Error: Type of symbol second_xc_function has mismatch with previous definition:
../xc_functions.xc: Error: found: void second_xc_function(struct &)
c_functions.c: Error: previous: void second_xc_function(struct *)
Please see my attached project showing the compilation errors. In the project, the issue is removed by removing "chanend *movable c;" from MyStruct, but so is the functionality I'm after.
The "Calling between C/C++ and XC" document shows examples of how to perform similar operations, but does not provide much depth.
https://www.xmos.com/download/private/C ... 65A%29.pdf
Is there a way to do what I'm after?
Code: Select all
#include <xccompat.h>
#ifndef __XC__
#define movable
#endif
typedef struct
{
unsigned a;
unsigned b;
chanend *movable c;
} MyStruct;
c_functions.c: Error: Type of symbol first_c_function has mismatch with previous definition:
c_functions.c: Error: found: void first_c_function(struct *)
../main.xc: Error: previous: void first_c_function(struct &)
../xc_functions.xc: Error: Type of symbol second_xc_function has mismatch with previous definition:
../xc_functions.xc: Error: found: void second_xc_function(struct &)
c_functions.c: Error: previous: void second_xc_function(struct *)
Please see my attached project showing the compilation errors. In the project, the issue is removed by removing "chanend *movable c;" from MyStruct, but so is the functionality I'm after.
The "Calling between C/C++ and XC" document shows examples of how to perform similar operations, but does not provide much depth.
https://www.xmos.com/download/private/C ... 65A%29.pdf
Is there a way to do what I'm after?