ambiguous code generation

I have a project, written on matlab. When I try to translate it into C/C++ by MATLAB Coder, some functions get their copies named name_of_functon1.c in addition to name_of_functon.c. Some other functions have only name_of_functon.c, and third kind of functions have only name_of_functon1.c files.
Is there some rule: whether create copy of file or not, and what does "1" means, if there is only one file?

Answers (1)

John Elliott
John Elliott on 12 Jul 2011
Numeric suffixes are added to file names to ensure uniqueness. If you have a function that is called once with, say, a double array and a second time with a single array, there may be two C files generated for that function, one suffixed with '1' and the other with no suffix. Can you give an example of a case where a single file has the suffix '1'?

3 Comments

For examle:
I have such a function:
function Mix = mixture_law(blklen)
%#codegen
t = 0:24;
Q1 = 0.51; Q2 = 0.49;
C1 = Q1/(Q1-Q2); C2 = Q2/(Q2-Q1);
Poly = C1*Q1.^t+C2*Q2.^t;
Mix = ones(blklen, 1)*Poly;
Input is always double 1x1. MATLAB Coder returns file mixture_law1.c:
/*
* mixture_law1.c
*
* Code generation for function 'mixture_law1'
*
* C source code generated on: Tue Jul 12 17:20:59 2011
*
*/
/* Include files */
#include "rt_nonfinite.h"
....(other #includes)
/* Type Definitions */
/* Named Constants */
/* Variable Declarations */
/* Variable Definitions */
/* Function Declarations */
/* Function Definitions */
/*
* function Mix = mixture_law(blklen)
*/
void mixture_law(real_T blklen, emxArray_real_T *Mix)
{
int32_T blklen_idx_0;
int32_T i50;
int32_T loop_ub;
int32_T i51;
static const real_T b[25] = { 1.0, 1.0, 0.75010000000000066,
0.50020000000000042, 0.3127500099999998, 0.1877500299999999,
0.10959380250099998, 0.062675070004000022, 0.0352875787590001,
0.019625078765000498, 0.010806712833126373, 0.0059024056497527493,
0.0032018081127544711, 0.0017267969408812566, 0.00092666509350391481,
0.00049513853797768877, 0.00026356493111106053, 0.0001398298104704361,
7.3964934185782061E-5, 3.9021464549220073E-5, 2.0537627496193149E-5,
1.0786163505343047E-5, 5.65381039404438E-6, 2.9583481340591521E-6,
1.545460916587462E-6 };
blklen_idx_0 = (int32_T)blklen;
i50 = Mix->size[0] * Mix->size[1];
Mix->size[0] = blklen_idx_0;
Mix->size[1] = 25;
emxEnsureCapacity((emxArray__common *)Mix, i50, (int32_T)sizeof(real_T));
for (i50 = 0; i50 < 25; i50++) {
loop_ub = blklen_idx_0 - 1;
for (i51 = 0; i51 <= loop_ub; i51++) {
Mix->data[i51 + Mix->size[0] * i50] = b[i50];
}
}
}
/* End of code generation (mixture_law1.c) */
and there's no file mixture_law.c
By the way, sometimes in file function_name.c one can see
void b_function_name(input_parameters1) {
...
}
void c_function_name(input_parameters2) {
...
}
void d_function_name(input_parameters3) {
...
}
Is it not the same situation, as You have described?
This is a similar situation. In this case, uniqueness is maintained for each function *within* a file (rather than the file name itself). The reason for the multiple C functions is again because the same MATLAB function is called with different types of arguments.
With respect to your original question concerning the single file with the '1' suffix, can you also provide the MATLAB commands that you used to compile your example?

Sign in to comment.

Products

Asked:

on 12 Jul 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!