Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the default CPP code different from that in MATLAB official documentation? #2

Open
Silver-Fang opened this issue Nov 11, 2021 · 4 comments

Comments

@Silver-Fang
Copy link

The default code created is like:

#include "mex.h"

void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
    mexPrintf("hello, world\n");
}

But in MATLAB documentation:

#include "mex.hpp"
#include "mexAdapter.hpp"

class MexFunction : public matlab::mex::Function {
public:
    void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
        // Function implementation
        ...
    }
};
@AndyYangjd
Copy link

It seems not difference. The default code is c-style, but the code in Matlab documentaion which you show is cpp-style.

@Silver-Fang
Copy link
Author

It seems not difference. The default code is c-style, but the code in Matlab documentaion which you show is cpp-style.

I think I have chosen somewhere to use cpp, and the code file itself is cpp.

@gharveymn
Copy link
Owner

gharveymn commented Aug 9, 2022

Ah, sorry that I never responded to this.

The C style default is used if you select Matrix API in the wizard. The Matrix API may be used with either C or C++ code, and is backwards compatible with older versions of MATLAB.

Your second example should be the code that is generated if you were to select Data API in the wizard.

I hope that helps explain things.

@AndyYangjd
Copy link

AndyYangjd commented Aug 9, 2022

I think I have chosen somewhere to use cpp, and the code file itself is cpp.

In fact, i also use cpp, but many people in our country choose to use matlab, so i have to wrap the c/c++ code to matlab/simulink for them.

The operation mechanism in simulink is c-style for embeded development. So if your code is c++(object-oriented, OOD), you have to wrap your cpp code with pointer. This warp can be done in a c file or in s-function defination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants