Info

This question is closed. Reopen it to edit or answer.

emlc C code generation error "Unable to apply the reference parameter optimization"

1 view (last 30 days)
I have a code base with several M functions I am converting to be included into an existing C code base. I am trying to limit the input by value overhead of large structures so created a glob structure. Some data is input, some output, some are persistent.
I have 2 functions which use this same global structure.
function [glob] = foo_gen
Data = struct('Input',zeros(8,1),'Output',zeros(8,1),'State',zeros(1));
eml.cstructname(Data,'DataStruct_t');
glob = struct('AllData',repmat(Data,3,1));
eml.cstructname(glob,'GlobalStruct_t');
end
function [glob] = foo(glob)
eml.cstructname(glob,'GlobalStruct_t');
eml.cstructname(glob.AllData(1),'DataStruct_t');
glob.AllData(1).Output = glob.AllData(1).Input;
end
I have many difficulties with getting this compile. Sometimes, it errors out that the tpyes do not match or is reused when the foo and foo_gen do not match exactly. It errors out if the foo function encapsulates the eml.cstructnames in an if ~isempty(eml.target) block.
I am using a multiple-entry point emlc invocation: emlc -c -s rtw_config -d ..\M_Code_Release foo -eg {glob} foo_gen
What does the error message "Unable to apply the reference parameter optimization to 'glob' of function 'foo'" mean and how do I fix it. The suggestion is to rewrite the code to not have outputs and inputs with matching names but my real code would be unworkable like that.

Answers (1)

Fred Smith
Fred Smith on 15 Apr 2013
This sounds like a bug. What version of MATLAB are you using?
Your example worked in the latest version of MATLAB after upgrading to the latest syntax:
.m:
function [glob] = foo(glob)
coder.cstructname(glob,'GlobalStruct_t');
coder.cstructname(glob.AllData(1),'DataStruct_t');
glob.AllData(1).Output = glob.AllData(1).Input;
end
foo_gen.m:
function [glob] = foo_gen
Data = struct('Input',zeros(8,1),'Output',zeros(8,1),'State',zeros(1));
coder.cstructname(Data,'DataStruct_t');
glob = struct('AllData',repmat(Data,3,1));
coder.cstructname(glob,'GlobalStruct_t');
end
doit.m:
glob = foo_gen;
codegen -c -config:lib -d ..\M_Code_Release foo -args {glob} foo_gen

This question is closed.

Products

Community Treasure Hunt

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

Start Hunting!