make visible struct and class from C to XC

Technical questions regarding the XTC tools and programming with XMOS.
cicga
Active Member
Posts: 51
Joined: Tue Oct 11, 2011 4:48 pm

make visible struct and class from C to XC

Post by cicga »

Hi all,

how one can make visible struct and class from C/C++ to XC ?
for make array visible you just put :

extern int arr[];...and it become usable from XC.

but I have hard time to pass struct to XC.


thx

cicga


User avatar
Lele
Active Member
Posts: 52
Joined: Mon Oct 31, 2011 4:08 pm

Post by Lele »

Hi, it is the same as C: typedef the struct in an include (.h) file

Code: Select all

#ifndef C_INCLUDE_H_
#define C_INCLUDE_H_

struct tagSTRUCT_NAME
{
  int Param0;
  char Vector[100];
};
typedef struct tagSTRUCT_NAME STRUCT_NAME;

#endif /* C_INCLUDE_H_ */
then include it and allocate the struct in the C source:

Code: Select all

#include "CHeader.h"

STRUCT_NAME Struct;
finally you can refer to the struct data from .xc source

Code: Select all

#include "CHeader.h"

extern SRUCT_NAME Struct;

int main() {
  Struct.Param0 = 0;
  return 0;
}
cicga
Active Member
Posts: 51
Joined: Tue Oct 11, 2011 4:48 pm

Post by cicga »

thx Lele...