Matlab 2020A Matlab Coder Use C style EmxArray Bug

6 views (last 30 days)
Hi everyone,
I am having problems with the new MATLAB Coder app. Before Matlab 2020a, if your target code was C++, variable size output format was emxArray type. Since 2020a, it has been changed to coder::array type by default. But in the link below it says that if you still want your output variables to be in C format (emxArray) while your target is C++, go to Memory Tab and change the dynamic memory allocation interface to --> Use C style EmxArray. I am doing this but it still generates coder_array.h file and all input/outputs are in coder::array (C++) format. Is it a bug? Has anyone tried this before? I would be pleased if you tell me what I am missing. Thank you.

Accepted Answer

Andy
Andy on 10 Apr 2020
Hi dober dober,
Unfortunatly, it looks like this is a bug in our 2020A release of MATLAB Coder.
You can work around this by doing the following:
- In the app toolbar, click the action menu (in the top right corner), and then select Convert to script.
- Specify the script name and click Save.
- Open the script file in the editor, you should see a piece of code that looks something like this:
%% Create configuration object of class 'coder.EmbeddedCodeConfig'.
cfg = coder.config('lib','ecoder',true);
cfg.GenerateReport = true;
cfg.ReportPotentialDifferences = false;
cfg.DynamicMemoryAllocationInterface = 'C++'; % <---- Edit this line to say 'C'
cfg.TargetLang = 'C++';
cfg.GenCodeOnly = true;
cfg.TargetLangStandard = 'C++03 (ISO)';
- Edit the line that says "cfg.DynamicMemoryAllocationInterface = 'C++';" to say "cfg.DynamicMemoryAllocationInterface = 'C';
- Move this line so that it is after the line "cfg.TargetLang = 'C++';" The final result should look something like this:
%% Create configuration object of class 'coder.EmbeddedCodeConfig'.
cfg = coder.config('lib','ecoder',true);
cfg.GenerateReport = true;
cfg.ReportPotentialDifferences = false;
cfg.TargetLang = 'C++'; % <---- Swap these two lines
cfg.DynamicMemoryAllocationInterface = 'C'; % <----
cfg.GenCodeOnly = true;
cfg.TargetLangStandard = 'C++03 (ISO)';
The bug seems the be the cfg.TargetLang = 'C++' will overwrite the configuration option cfg.DynamicMemoryAllocationInterface with its default value (e.g. C++).
I apoligize for the inconvenience. In future versions this should be resolved and we'll look into fixing this in an update.
Thanks for pointing this out,
-Andy

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!