Avoid generating empty functions with Simulink Embedded Coder

13 views (last 30 days)
Hi, I'm generating C code from a Simulink model using Embedded Coder on Matlab R2017a. By default two functions are created, step and initialize. For my Simulink model, the initalize function is empty. Is there a way of avoiding generating the initialize function if it is going to be empty? The generation of this empty function creates some problems on the postprocessing of the generated C code by another tool so I was wondering if I could configure Embedded Coder not to generate empty functions.
Thanks in advance.

Answers (1)

Kanishk
Kanishk on 21 Jan 2025
Edited: Kanishk on 21 Jan 2025
When generating C code from a Simulink model using Embedded Coder, the code generation process typically includes the “initialize”, “step” and “terminate” functions. However, if one of these functions is empty, there is currently no option to stop it from generating as Simulink mostly generates these functions as part of boiler plate code.
During the build process, “gcc” handles and removes the empty functions automatically as part of optimizations. You can also add custom optimization flags such ‘-O3’ in Simulink using ‘SimCustomCompilerFlags’.
set_param(gcs, 'SimCustomCompilerFlags', '-O3')
If possible, You can then safely remove any check for identifying empty functions from the tool you are using.
A workaround for removing empty functions from generated code can be using a post-processing script. Empty functions can be identified using regular expressions and can be removed. All files are needed to be examined by the script to remove the function calls and function definitions from header files.
You can access the documentation for adding Custom compiler flags and using regular expressions in MATLAB using the following commands.
web(fullfile(docroot, 'simulink/gui/compiler-flags.html'))
web(fullfile(docroot, 'matlab/matlab_prog/regular-expressions.html'))

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!