MATLAB: Matlab coder automatically inlines m file returning multiple values

codermatlab coder

I have a coder project with 2 .m files. The main .m file calls another .m file that returns multiple values. When I generate c files for the project, it automatically inlines the c code for the 2nd .m file in the c file for the main .m file (i.e. the c file generated for the 2nd .m is not used at all). I understand c functions can't return multiple values, but should the coder at least issue a warning and provide suggestions how to change the m code if I want to maintain the design hierarchy?

Best Answer

Although I'm not an expert in the inlining heuristics of the compiler, I'm not aware that inlining has anything to do with the number of outputs. I should think at most it would imply a slight bias. Normally functions get inlined if they are short. You have both general and specific tools for controlling this. The general tool is
>> cfg = coder.config('lib');
>> cfg.InlineThreshold = 0;
>> codegen foo -args {blah1,blah2} -config cfg -report
This is a kind of "nuclear option". You can use a slightly larger InlineThreshold if you do want trivial functions inlined.
The specific method (and what I recommend) is
coder.inline('always')
coder.inline('never')
If you want the compiler to inline things automatically within toolbox functions but not to inline functions that you write, then you can just put coder.inline('never') at the top of each of your functions. -- Mike
Related Question