I am trying to learn how to use legacy code tool but I am not succeding, maybe because I am a beginner in C, but also because the documentation it is not so complete.
I have this C function add_array, the main is just to test the output:
void add_array (int *a, int num_elements, int *final);
int Tab[5] = {1000, 220, 37, 16, 98};
add_array(Tab, 5, &final);
printf("Total summation is %d\n", final);
void add_array (int *p, int size, int *final)
for (k = 0; k < size; k++)
total += p[k]; /* it is equivalent to total +=*p ;p++; */
Which output is the sum of the element of the int array: Total summation is 1371
extern void add_array (int32_T *p, int32_T size, int32_T *final)
for (k = 0; k < size; k++)
total += p[k]; /* it is equivalent to total +=*p ;p++; */
I have also created an header called add_veg.h:
#ifndef ADD_VEG_H_INCLUDED
#define ADD_VEG_H_INCLUDED
void add_array (int32_T *p, int32_T size, int32_T *final);
#endif // ADD__VEG_INCLUDED
And this is my matlab script to create the s function with the legacy tool:
sf = legacy_code('initialize');
sf.SFunctionName = 'vegekou';
sf.OutputFcnSpec = 'void(int32 u1[5], int32 u2, int32 y1)';
sf.HeaderFiles = {'add_veg.h'};
sf.SourceFiles = {'vegeta3.c'};
legacy_code('sfcn_cmex_generate', sf);
legacy_code('compile',sf);
I receive a lot of errors when trying to compile:
C:\sfun\c_code\return_array\vegekou.c(168): error C2143: syntax error: missing ')' before ','
C:\sfun\c_code\return_array\vegekou.c(168): error C2040: 'u1': 'int' differs in levels of indirection from 'int32_T *'
C:\sfun\c_code\return_array\vegekou.c(168): error C2086: 'int32_T *u2': redefinition
C:\sfun\c_code\return_array\vegekou.c(163): note: see declaration of 'u2'
C:\sfun\c_code\return_array\vegekou.c(168): error C2059: syntax error: ')'
C:\sfun\c_code\return_array\vegekou.c(168): error C2086: 'int32_T *y1': redefinition
C:\sfun\c_code\return_array\vegekou.c(164): note: see declaration of 'y1'
Error in legacycode.LCT/compile
Error in legacycode.LCT.legacyCodeImpl
Error in legacy_code (line 101)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
Error in legacy_vegeta (line 12)
legacy_code('compile',sf);
What am I doing wrong and how can I solve this?
I do not want to have y1 as output on the right of = in sf.OutputFcnSpec and add_array as a return function. Because I would like in the future to write a similar void function where there is an array output and I have observed that if y1 is a normal output on the right , legacy tool gives error saying that I can only use integers as outputs.
Thanks a lot in advance.