coder.nonInlineCall - Prevent inlining of called function in generated code - MATLAB (original) (raw)
Prevent inlining of called function in generated code
Since R2024a
Syntax
Description
`out` = coder.nonInlineCall([functionCall](#mw%5F238db17d-6422-454c-bbd6-fe81715ad768))
evaluates functionCall
and prevents the inlining of this function in the generated code. The functionCall
can take one or more input arguments and can return a single output. Use coder.nonInlineCall
when you want to simplify the mapping between the MATLAB® source code and the generated code. The coder.nonInlineCall
function overrides coder.inline directives in the called function.
The coder.nonInlineCall
function does not prevent the inlining of:
- Empty functions
- Functions that return constant output
To prevent inlining even in these situations, use the coder.ignoreConst function on an input at the function call site in your MATLAB code. For more information, see Resolve Issue: coder.inline("never") and coder.nonInlineCall Do Not Prevent Function Inlining.
`[out1,...,outN]` = coder.nonInlineCall([handle](#mw%5F86f69670-cba5-4394-959e-01dbe56966ed),[arg1,...,argN](#mw%5Feda9b467-6e85-444d-a607-e688358dcb4b))
calls the function with handle handle
, which can have one or more input arguments, and instructs the code generator not to inline this function in the generated code. The specified function can have more than one output.
Examples
Create the local function local_Inline
that returns the square of the input value and includes the directive coder.inline("always")
. Create the entry-point function useNonInlineCall
that calls local_Inline
using coder.nonInlineCall
to override the coder.inline("always")
directive.
function x = useNonInlineCall(n) %#codegen arguments n (1,1) double end x = coder.nonInlineCall(local_Inline(n)); end
function y = local_Inline(x) coder.inline("always"); y = x^2; end
Generate C code for useNonInlineCall
and inspect the entry-point function in the generated code. The code generator overrides the coder.inline("always")
directive, preventing the inlining of local_Inline
in the generated code.
codegen -config:lib useNonInlineCall
Warning: Code generation is using a coder.EmbeddedCodeConfig object. Because Embedded Coder is not installed, this might cause some Embedded Coder features to fail.
Code generation successful (with warnings): View report
type(fullfile("codegen","lib","useNonInlineCall","useNonInlineCall.c"))
/*
- Prerelease License - for engineering feedback and testing purposes
- only. Not for sale.
- File: useNonInlineCall.c
- MATLAB Coder version : 25.1
- C/C++ source code generated on : 01-Feb-2025 08:03:18 */
/* Include Files */ #include "useNonInlineCall.h"
/* Function Declarations */ static double local_Inline(double x);
/* Function Definitions / /
- Arguments : double x
- Return Type : double */ static double local_Inline(double x) { return x * x; }
/*
- Arguments : double n
- Return Type : double */ double useNonInlineCall(double n) { return local_Inline(n); }
/*
- File trailer for useNonInlineCall.c
- [EOF] */
Create the local function circleMath
that takes the radius of a circle as input and returns two outputs, circle area and circumference. Create the entry-point function multiOutputNonInlineCall
that uses coder.nonInlineCall
to call the function handle for circleMath
and to instruct the code generator not to inline this function.
type multiOutputNonInlineCall.m
function [area, circ] = multiOutputNonInlineCall(radius) %#codegen arguments radius (1,1) double end [area, circ] = coder.nonInlineCall(@circleMath,radius); end
function [a,c] = circleMath(r) coder.inline("always"); a = pir^2; c = pi2*r; end
Generate C code for multiOutputNonInlineCall
and inspect the entry-point function in the generated code. The code generator overrides the coder.inline("always")
directive and prevents the inlining of circleMath
in the generated code.
codegen -config:lib multiOutputNonInlineCall
Warning: Code generation is using a coder.EmbeddedCodeConfig object. Because Embedded Coder is not installed, this might cause some Embedded Coder features to fail.
Code generation successful (with warnings): View report
type(fullfile("codegen","lib","multiOutputNonInlineCall","multiOutputNonInlineCall.c"))
/*
- Prerelease License - for engineering feedback and testing purposes
- only. Not for sale.
- File: multiOutputNonInlineCall.c
- MATLAB Coder version : 25.1
- C/C++ source code generated on : 01-Feb-2025 08:03:21 */
/* Include Files */ #include "multiOutputNonInlineCall.h"
/* Function Declarations */ static double circleMath(double r, double *c);
/* Function Definitions / /
- Arguments : double r
double *c
- Return Type : double */ static double circleMath(double r, double *c) { double a; a = 3.1415926535897931 * (r * r); *c = 6.2831853071795862 * r; return a; }
/*
- Arguments : double radius
double *area
double *circ
- Return Type : void */ void multiOutputNonInlineCall(double radius, double *area, double *circ) { *area = circleMath(radius, circ); }
/*
- File trailer for multiOutputNonInlineCall.c
- [EOF] */
Input Arguments
Function call to evaluate and not inline in the generated code, specified as a function name optionally followed by a comma-separated list of one or more arguments in parentheses. The specified function can return at most one output argument.
Example: coder.nonInlineCall(myFunction(arg1,arg2))
Example: out = coder.nonInlineCall(myFunction)
Handle to a MathWorks® or user-written function. This function can have multiple outputs.
Example: [out1,out2] = coder.nonInlineCall(@myFunction)
Data Types: function handle
Inputs to the function with handle handle
, specified as a comma-separated list of function arguments. The types of the inputs depend on the called function.
Example: out = coder.inlineCall(@myFunction,10,"myString")
Extended Capabilities
Version History
Introduced in R2024a