Why does a struct in my MATLAB Function not show up in the generated C++ code?

I am using MATLAB Coder to generate C++ code for a MATLAB function containing a struct. When I generate C++ code, I find that it does not contain any of the structure declarations I had in the original MATLAB function. Why? Also, output C++ code has no Class structure, just straight 'C' type code! Why? Does original MATLAB code have to be object oriented design? 

 Accepted Answer

This is likely due to MATLAB Coder discarding data structures if they are not being used in the code. Essentially, MATLAB Coder runs optimizations when converting code to C or C++ and decides to sometimes discard extraneous data structures in the interest of speed and efficiency of the generated code. To better illustrate this, I am attaching two MATLAB functions - "trial_noStruct.m" and "trial_withStruct.m". The first function declares a struct but does not perform any operations with it, whereas the second function declares the struct and returns it as the output. When you proceed to generate code for the two functions, you will find that "trial_noStruct.m" does not generate a struct while "trial_withStruct.m" does.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Release

R2016a

Community Treasure Hunt

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

Start Hunting!