StackData macro not generated for C++

4 ビュー (過去 30 日間)
Alexander Söderqvist
Alexander Söderqvist 2021 年 4 月 27 日
編集済み: Ryan Livingston 2021 年 4 月 30 日
Hi,
we are using matlab coder to generate C-code according to defined function interface, we use this to develop stand alone libraries with different functionality. Sometimes the C-functions that are generated takes a variable <function_name>StackData as first parameter, this can be detected via generated macro called typedef_<function_name>StackData. The type of this variable and the macro are specifed in a file called <function_name>_types.h. Including this file and checking if this macro exists allows us to write code which always adhere to the signature of the function. So far all is good.
Some time ago I wanted try to generate C++ code: and also when generating C++ code the functions sometimes takes the <function_name>StackData as first argument, however there are NO macro defined which allows us to detect this, hence I can not adhere to the signature of the function. This is effectively keeping us from generating C++ code, which would be more suitable as this is what the surrounding software is written in.
Is the fact that no macro is generated in C++ mode a bug? Or is there another explanation for this...
BTW, I am using R2019b.
  2 件のコメント
Darshan Ramakant Bhat
Darshan Ramakant Bhat 2021 年 4 月 29 日
I have tried the code generation using the attached files. In the C++ code I can see the below stuct in "fooNorm_types.h" file :
// Type Definitions
struct fooNormStackData
{
struct {
unsigned int b[100000];
} f0;
};
Are you expecting something different ?
Below document explains the scenarios in which the stackData is getting generated :
Alexander Söderqvist
Alexander Söderqvist 2021 年 4 月 29 日
編集済み: Alexander Söderqvist 2021 年 4 月 29 日
The struct, when needed as first argument to the function, is generated also in C++ mode, yes. However in C-mode I also get a macro generated, which allows me to detect whether the function actually takes the struct as first argument or not. This is how it looks in C-mode, and what I would expect also from C++-mode:
#ifndef typedef_fooStackData
#define typedef_fooStackData
typedef struct {
struct {
double foovar[968256];
} f0;
} fooStackData;
#endif /*typedef_fooStackData*/

サインインしてコメントする。

採用された回答

Ryan Livingston
Ryan Livingston 2021 年 4 月 29 日
編集済み: Ryan Livingston 2021 年 4 月 30 日
It is by design that the typedef guards are not present in C++. The use case you describe here is not one we had in mind for them. The fact that the generated function changes signature in an unpredictable manner seems like the root issue to me. We've made an internal note for the MATLAB Coder team to look at addressing this in the future.
Since you're in R2019b and interested in C++, I'd suggest taking a look at the ability to package the generated code into a class rather than free functions. That will give you a class with one or more entry-point methods which are independent of the stackData argument. That data will be stored as a class property thereby giving you a consistent interface.
cfg.CppInterfaceStyle = 'Methods';
cfg.CppInterfaceClassName = 'Interface';
codegn -config cfg ...
will enable that and produce a class like:
class Interface
{
public:
Interface();
~Interface();
real_T entryPointFunction(real_T n);
fStackData *getStackData();
private:
fStackData SD_;
};
Where entryPointFunction is your entry-point. Then, on the calling side you can instantiate the object and just call the method without having to pass stackData.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGenerating Code についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by