mex: valid c code crashes Matlab. (integer pointer)
Mostrar comentarios más antiguos
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 comentario
Gary Pajer
el 19 de Ag. de 2016
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre C Shared Library Integration en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!