MATLAB Answers

What is the difference in goal between C Caller and C Mex ?

4 views (last 30 days)
Muhammad Alhaddad
Muhammad Alhaddad on 29 Feb 2020
Commented: Walter Roberson on 3 Mar 2020
I have understood that C Caller is used to implement script which is written in C in Simulink, but in S-Function C mex we can do the same thing so what is the difference between them and if they do the same thing which one is better?

  1 Comment

Walter Roberson
Walter Roberson on 29 Feb 2020
Good question. I had not heard of C Caller before.
The main difference I see listed is that it cannot be used for continuous time.
S Function is said to be used for dynamic systems, but at the moment I do not know what the implications of that are. I think S Function can manipulate model state but the C Caller is not designed for that.

Sign in to comment.

Answers (1)

Dinesh Yadav
Dinesh Yadav on 3 Mar 2020
There is no difference in goal between C Caller and S-functions. Both are used to call C code in simulink. However they differ in terms of simplicity of use and flexibilty they provide.
  • In C caller one can call C code directly and for C++ code one needs to write C wrapper function around C++ code, but in S-function one can call C/C++ code directly.
  • C Caller block is simpler to implement as compared to S-function. For reference type sfundemos in MATLAB command prompt and go through code of any C?C++ S-function and slexCCallerExample to see C Caller example.
  • S-functions have lots of api's as compared to C Caller which makes S-functions more flexible and can be used to implement more complex systems as compared to C Caller blocks. However if one wants to implement basic and simple systems its easier and faster to use C Caller blocks.
  • When calling external C/C++ code or .dll/.so one can perform debugging using Visual Studio etc in S-functions but same cannot be done in C Caller.

  1 Comment

Walter Roberson
Walter Roberson on 3 Mar 2020
Thanks for the summary!
Which of the two has lower overhead? I suspect it would be C Caller?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!