mex: valid c code crashes Matlab. (integer pointer)
显示 更早的评论
This code compiles, but crashes Matlab. The same code written and compiled as straight c works fine.
#include "mex.h"
#include <stdio.h>
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
//int z =11;
int *x = 1;
*x = 14;
printf("*x = %d\n", *x);
}
With this small change it works fine. Should I have expected this behavior?
#include "mex.h"
#include <stdio.h>
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
int z =11;
int *x = &z;
*x = 14;
printf("*x = %d\n", *x);
}
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!