MATLAB: MATLAB Coder incomplete conversion

cfunctionsmatlab coder

Hi,
I'm trying to convert a little algorithm (about 35 files / 5000 rows of code).
I made some adjustments to the code:
– The unsupported functions have been wrapped in an hollow body function that return the same type of results as the original function. When the code will be ready, I will replace them with the ones found in an external library
– I fixed the code to clear any error that may appear in the "Check for run-time issues"
– The "Generated file partitioning method" has been set to "Generate one file for each MATLAB file"
– I placed the coder.inline('never') instruction in every function to avoid any optimization and understand better the generated code
I can correctly generate the C++ code without any error but when i look at the code I can see that not everything has been converted, some call in the middle are missing, event if i used the coder.inline('never') instruction! Also the wrapped unsupported functions are missing….
Am I missing something?
Thanks in advance
Paul

Best Answer

Hi Paolo,
The coder.inline('never') command specifies to turns off the function inlining optimization for a given function. If you want to disable inlining for all functions you can pass the following to the codegen command:
-O disable:inline
There are other optimizations and code transformatiosn that MATLAB Coder performs, not all of them can be turned off, so your code may change in other ways despite using coder.inline('never'). In your case I think MATLAB coder's constant folding algorithm removes functions that do nothing.
What I'd suggest doing is "trick" this optimization into thinking the function may have a side-effect by inserting a call to coder.ceval('//') into it. In other words do what we do in bar here:
function out = test()
bar();
out = 42;
end
function bar()
coder.inline('never');
coder.ceval('//');
end
For more suggestions on how to determine how the generated code relates to your original MALTAB code you may want to look here:
https://www.mathworks.com/help/coder/ug/tracing-between-generated-cc-code-and-matlab-code.html
Hope that helps,
-Andy