| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Real-Time Workshop |
| Contents | Index |
| Learn more about Real-Time Workshop |
If you need to integrate external C code with generated C++ code or vice versa, you must modify your external code to be language compatible with the generated code. Options for making the code language compatible include
Writing or rewriting the legacy or custom code in the same language as the generated code.
If the generated code is in C++ and your legacy or custom code is in C, for each C function, create a header file that prototypes the function, using the following format:
#ifdef __cplusplus
extern "C" {
#endif
int my_c_function_wrapper();
#ifdef __cplusplus
}
#endifThe prototype serves as a function wrapper. The value __cplusplus is defined if your compiler supports C++ code. The linkage specification extern "C" specifies C linkage with no name mangling.
If the generated code is in C and your legacy or custom code is in C++, include an extern "C" linkage specification in each .cpp file. For example, the following shows a portion of C++ code in the file my_func.cpp:
extern "C" {
int my_cpp_function()
{
...
}
}![]() | Integration Options | Integrating External Code Using Model Configuration Parameters | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |