Resolve Issue: coder.inline('never')
Does Not Prevent Inlining of
Function
Issue
In cases where the coder.inline('never')
directive does not
prevent inlining of a MATLAB® function, the code generator removes the function and replaces it with
a constant computed return value, even if the function contains
coder.inline('never')
.
For example, consider these functions:
function y = test_inline() x = local(0); if(x == 0) y = 0; else y = 1; end end function y = local(x) coder.inline('never'); y = x; end
test_inline
function calls local
with a
constant input value. The generated code for test_inline
is:double test_inline(void) { return 0.0; }
local
and returns a constant value, even
though the MATLAB definition contains the coder.inline('never')
directive.Possible Solutions
To resolve the issue and prevent the code generator from inlining a function, use
the coder.ignoreConst
function on an input
at the function call site in your MATLAB code. This prevents the code generator from returning the function
output as a constant value.
Consider this code snippet:
function y = test_inline() x = local(coder.ignoreConst(0)); if(x == 0) y = 0; else y = 1; end end function y = local(x) coder.inline('never'); y = x; end
The generated code for the functions is:
static double local(void) { return 0.0; } double test_inline(void) { return !(local() == 0.0); }
See Also
coder.ignoreConst
| coder.inline