Main Content

coder.nonInlineCall

Prevent inlining of called function in generated code

Since R2024a

    Description

    out = coder.nonInlineCall(functionCall) 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.

    example

    [out1,...,outN] = coder.nonInlineCall(handle,arg1,...,argN) 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.

    example

    Examples

    collapse all

    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.

    type useNonInlineCall.m
    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): To view the report, open('codegen/lib/useNonInlineCall/html/report.mldatx')
    
    type(fullfile("codegen","lib","useNonInlineCall","useNonInlineCall.c"))
    /*
     * File: useNonInlineCall.c
     *
     * MATLAB Coder version            : 24.2
     * C/C++ source code generated on  : 05-Sep-2024 16:35:23
     */
    
    /* 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 = pi*r^2;
    c = pi*2*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): To view the report, open('codegen/lib/multiOutputNonInlineCall/html/report.mldatx')
    
    type(fullfile("codegen","lib","multiOutputNonInlineCall","multiOutputNonInlineCall.c"))
    /*
     * File: multiOutputNonInlineCall.c
     *
     * MATLAB Coder version            : 24.2
     * C/C++ source code generated on  : 05-Sep-2024 16:35:28
     */
    
    /* 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

    collapse all

    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

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    GPU Code Generation
    Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

    Version History

    Introduced in R2024a