Main Content

S-Functions That Support Code Reuse

You can reuse the generated code for identical subsystems that occur in multiple instances within a model and across referenced models. For more information about code generation of subsystems for code reuse, see Control Generation of Functions for Subsystems. If you want your S-function to support code reuse for a subsystem, the S-function must meet these requirements:

  • The S-function must be inlined.

  • Code generated from the S-function must not use static variables.

  • The S-function must initialize its pointer work vector in mdlStart and not before.

  • The S-function must not be a sink that logs data to the workspace.

  • The S-function must register its parameters as run-time parameters in mdlSetWorkWidths. (It must not use ssWriteRTWParameters in its mdlRTW function for this purpose.)

  • The S-function must not be a device driver.

In addition to meeting the preceding requirements, your S-function must set the SS_OPTION_WORKS_WITH_CODE_REUSE flag in the ssSetOptions function. This flag indicates that your S-function meets the requirements for subsystem code reuse.

Related Topics