matlabstaticglobal-variablessimulinks-function

Static Variables in Simulink S-Function Builder


I am currently working on the implementation of some C-Code in a Simulink model using the S-Function Builder block.

The code uses various timers and counters, which are defined as static variables to enable the access to the data in following simulation steps.

However, if I start the simulation MATLAB crashes without error message ('Fatal Exception'). To test I defined the variables without the 'static' statement. The Simulation works in this case, however with (logically) wrong results of the S-Function.

Has anybody else faced similar issues or knows how to declare static variables in Simulink?

P.S.

I know I could use Work Vectors, which I do not intend to do, since it would result in huge efforts in adopting the function to do so. Furthermore I could simply build a feed-back loop in the model using a memory block. For approximately 100 variables this solution would also be pretty impractical.


Solution

  • It seems like it was a bug in Simulink or the MinGW Compiler. However I tore down the code, ending up with it crashing with the call of one specific variable. I renamed the variable, since I could not find any error in the syntax. Now everything works fine...

    The variable name had various underscores and capital letters - in case anyone makes similar experiences.