| Writing S-Functions | ![]() |
The Inlined Code
The code generated when you inline your wrapper S-function is similar to the default generated code. The MdlTerminate function no longer contains a call to an empty function and the MdlOutputs function now directly calls my_alg.
void MdlOutputs(int_T tid)
{
/* Sin Block: <Root>/Sin */
rtB.Sin = rtP.Sin.Amplitude *
sin(rtP.Sin.Frequency * ssGetT(rtS) + rtP.Sin.Phase);
/* S-Function Block: <Root>/S-Function */
rtB.S_Function = my_alg(rtB.Sin);
/* Outport Block: <Root>/Out */
rtY.Out = rtB.S_Function;
}
In addition, wrapper.reg no longer creates a child SimStruct for the S-function since the generated code is calling my_alg directly. This eliminates over 1K of memory usage.
| The TLC S-Function Wrapper | Fully Inlined S-Functions | ![]() |