zrs5532
zrs5532

Reputation: 1

reuse C code in simulink

Is it possible that I call a c program from a stateflow chart, then I copy this chart, still in this same model, and execute both with out any conflict?

For example a C program like this:

int var;              // var is global
int myfunction(int n)
{
  var = var + n;
  return var;
}

i mean, treat them like two different entities and won't mess up with global variable.

btw, also without rename the function in source code, I've got a big program :)

Upvotes: 0

Views: 142

Answers (1)

Florian Castellane
Florian Castellane

Reputation: 1227

This is more a C - related issue. If you are using the same C function that operates on a global, then yes, all calls to this function will operate on the same variable. What you can do instead is make this variable local to each of the calling Stateflow states and then pass it to the C function. This way you should not have conflicts and be able to reuse your code. It's also a good design choice since you otherwise are potentially hiding a state variable in the function i.e. outside of your state machine.

Upvotes: 0

Related Questions