coder.inlineCall - Inline called function in generated code - MATLAB (original) (raw)

Inline called function in generated code

Since R2024a

Syntax

Description

`out` = coder.inlineCall([functionCall](#mw%5F19fd8f97-5a1c-4da7-afe8-d4b65b3ac118)) evaluates functionCall and inlines the called function in the generated code. The functionCall can take one or more input arguments and can return a single output. Use coder.inlineCall in your MATLAB® code to replace the function call with the body of the called function in the generated code.

Inlining eliminates the overhead of a function call and can create opportunities for further optimization of the generated C/C++ code. However, inlining can generate larger, more complex C/C++ code. The coder.inlineCall function overridescoder.inline (MATLAB Coder) directives in the called function.

The coder.inlineCall function does not support the inlining of:

example

`[out1,...,outN]` = coder.inlineCall([handle](#mw%5Fcf265274-6a45-468d-85bc-5762e9a784ef),[arg1,...,argN](#mw%5F1353de6b-5a78-49a1-aaf5-78e60ff19b09)) calls the function with handle handle, which can have one or more input arguments, and inlines this function in the generated code. The specified function can have more than one output.

example

Examples

collapse all

Create the local function local_NoInline that returns the square of the input value and includes the directive coder.inline("never"). Create the entry-point function useInlineCall that calls local_NoInline using coder.inlineCall to override the coder.inline("never") directive.

function x = useInlineCall(n) %#codegen arguments n (1,1) double end x = coder.inlineCall(local_NoInline(n)); end

function y = local_NoInline(x) coder.inline("never"); y = x^2; end

Generate C code for useInlineCall and inspect the entry-point function in the generated code. The code generator inlines local_NoInline, replacing the function call with the body of the function.

codegen -config:lib useInlineCall

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","useInlineCall","useInlineCall.c"))

/*

/* Include Files */ #include "useInlineCall.h"

/* Function Definitions / /

/*

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 multiOutputInlineCall that uses coder.inlineCall to call the function handle for circleMath and to instruct the code generator to inline this function.

type multiOutputInlineCall.m

function [area, circ] = multiOutputInlineCall(radius) %#codegen arguments radius (1,1) double end [area, circ] = coder.inlineCall(@circleMath,radius); end

function [a,c] = circleMath(r) coder.inline("never"); a = pir^2; c = pi2*r; end

Generate C code for multiOutputInlineCall and inspect the entry-point function in the generated code. The code generator overrides the coder.inline("never") directive and inlines circleMath in the generated code, replacing the function call with the body of the function.

codegen -config:lib multiOutputInlineCall

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","multiOutputInlineCall","multiOutputInlineCall.c"))

/*

/* Include Files */ #include "multiOutputInlineCall.h"

/* Function Definitions / /

/*

Input Arguments

collapse all

Function call to evaluate and 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.inlineCall(myFunction(10,"myString"))

Example: out = coder.inlineCall(myFunction)

Handle to a MathWorks® or user-written function. This function can have multiple outputs.

Example: [out1,out2] = coder.inlineCall(@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