Skip to content

Instantly share code, notes, and snippets.

@CitizenInsane
Created February 27, 2015 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CitizenInsane/88376e034571550a3b82 to your computer and use it in GitHub Desktop.
Save CitizenInsane/88376e034571550a3b82 to your computer and use it in GitHub Desktop.
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray* mx;
int ndim = 2;
int dims[] = {1, 1};
const char *invalidFieldNames[] = { " ", "&;", "0lala", "n!" };
int fieldCount = sizeof(invalidFieldNames)/sizeof(*invalidFieldNames);
// Arguments check
if (nrhs != 0) { mexErrMsgTxt("Must be called without input arguments."); return; }
if (nlhs > 1) { mexErrMsgTxt("Must be called with at most 1 output argument."); return; }
// Create a struct array with invalid field names
// NB: I know this is stupid, this is just to show that field names are not tested.
mx = mxCreateStructArray(ndim, dims, fieldCount, invalidFieldNames);
if (mx != NULL)
{
mexPrintf("Oops was able to create field with invalid names and return this into matlab ...\n");
if (nlhs > 0) { plhs[0] = mx; }
else { mxDestroyArray(mx); }
}
else
{
mexErrMsgTxt("Cool, I'm not allowed to create struct with stupid field names.\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment