Integrate External C/C++ Code Using C Function Blocks
Use the C Function block to call external C/C++ code from your model. Use the C Function block to:
Write C code to preprocess data to call a C function. Similarly, you can write C code to postprocess data after calling a C function.
Specify different code for simulation and code generation.
Call multiple C functions defined in your external code.
Initialize and work with persistent data cached in the block.
Allocate and deallocate memory.
To get started by configuring custom code sources in your Simulink® model, see Specify and Configure Custom C/C++ Code.
To call simple C code, use the C Caller block. To integrate a dynamic system using C code into your Simulink model, use the S-Function block.
Blocks
C Function | Integrate and call external C/C++ code from a Simulink model (Since R2020a) |
Objects
SymbolSpec | Query and configure C Function block data symbols (Since R2020a) |
Symbol | C Function block data symbol (Since R2020a) |
Model Settings
Topics
- Specify and Configure Custom C/C++ Code
Specify custom C/C++ headers, source files, and libraries, and configure custom code settings for your Simulink model.
- Integrate External C/C++ Code into Simulink Using C Function Blocks
Integrate and modify external C Code using C Function blocks.
- Modify States of a C Function Block Using Persistent Symbols
- Change Values of Signals Using C Function Block and Buses
- Access Elements of a Matrix Using Output Code in a C Function Block
- Use External Functions with Matrix Input in a C Function Block
- Define an Alias Type in a C Function Block
- Use Inherited Sizes in a C Function Block
- Use Enumerated Data in a C Function Block
- Interface with C++ Classes Using C Function Block
Use C Function block to interface directly with C++ classes defined in custom code.
- Debug Custom C/C++ Code
Debug custom C/C++ code from within Simulink.