Why does referece to variable size data using "coder.wref" translate to incompatible (pointer) type arguments?

3 views (last 30 days)
I am trying to use pointer references to variable size data with "coder.wref" and then generate DLL.
My current workflow can be illustrated as (please refer to the skeleton function below).
    (1) functionB --> (MATLAB Coder) --> functionB.dll
    (2) functionA --> (MATLAB Coder) --> functionA.dll
    (3) Use functionA.dll from a client program (integrate using Visual C/C++)
    <Code Listing>
    %---- functionB.m ---------------------------------
    function [ result ] = functionB( flg, result )
    %#codegen
        % Create dll using MATLAB Coder
        % Input/output specification: result [:inf×3]
        result = [result; rand(1,3)];
    end %-functionB-%
    %---- functionA.m ---------------------------------
    function functionA( flg, result )
    %#codegen
        coder.ceval('functionB_initialize');
        coder.ceval('functionB', flg, coder.wref(result) );
        coder.ceval('functionB_terminate');
    end %-functionA-%
As you may expect, using variable size data is used for "result" is realized as an emxArray type
and the following code is generated for functionB:
    // functionB.h
    extern void functionB(double flg, emxArray_real_T *result);
However, the arguments for calling the function (B) from functionA in the generated code
uses the pointer to the data field of the emxArray structure:
    // functionA.c
    void functionA(double flg, emxArray_real_T *result)
    {
        functionB_initialize();
        functionB(flg, &result->data[0]);
        functionB_terminate();
    }
    //functionB(flg, result);
To my understanding, this would simply give a "incompatible types" warning during the compilation.
If build can be successfull at all (ignoring the warning),
it is highly likely that the address of "result->data[0]" will differ from the intended address of "result"
and will produce something unexpected.
What can I do?
As an workaround I could think of manually changing the function call to
     functionB(flg, result);
 

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Jun 2015
Currently it is not possible to use "coder.ceval()" to call an interface which uses an emxArray.
"coder.ceval()" can only be used on types as specified by the documentation (which is basically primitive C types).
"emxArray" is a compound datatype used by the MATLAB Coder API for external interfacing for handwritten C code.
The APIs for using "emxArray"s are produced in "<filename>_emxAPI.cpp".
In general, MATLAB Coder doesn't support separate compilation and combining generated code.
If you still want to do it, please be aware of the problems that can occur such as generation of a wrong pointer (the one described above).
If you want a function to call another function and both need to be entry-points then it is recommended to use multiple entry-points.

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2014b

Community Treasure Hunt

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

Start Hunting!