mex: valid c code crashes Matlab. (integer pointer)
Ältere Kommentare anzeigen
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);
}
1 Kommentar
Gary Pajer
am 19 Aug. 2016
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu C Shared Library Integration finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!