我学习的书Accelerating MATLAB Performance和page 394,这个代码写的是:为什么这个MEX函数会产生意想不到的结果?
#include "mex.h"
void mexFunction (int nlhs,mxArray *plhs[],/*outputs*/
int nrhs, const mxArray *prhs[])/*inputs*/
{
const char *name = mexFunctionName();
printf("s() called with %d inputs,%d outputs\n",name,nrhs,nlhs);
}
基于什么是在书中说,建设MEX代码的命令mex hello.cpp
后,下面的结果应该产生:
>> hello
hello() called with 0 inputs, 0 outputs
>> hello(1,2,3)
hello() called with 3 inputs, 0 outputs
>> [a,b] = hello(1,2,3)
hello() called with 3 inputs, 2 outputs
One or more output arguments not assigned during call to "hello".
但是,当我在我的Win7x64
机器上运行相同的代码,结果如下:
>> mex hello.cpp
Building with 'Microsoft Visual C++ 2010'.
MEX completed successfully.
>> hello
s() called with 2082650752 inputs,0 outputs
>> hello(1,2,3)
s() called with 2082650752 inputs,3 outputs
>> [a,b] = hello(1,2,3)
s() called with 2082650752 inputs,3 outputs
One or more output arguments not assigned during call to "hello".
这些意外结果的原因是什么?
上面的链接没有显示我的页面,但通过搜索页面可以访问:https://goo.gl/dGg5HA书中的代码示例是错误的。 – Daniel
继[勘误](http://undocumentedmatlab.com/books/matlab-performance)之后,作者不知道,我给他发了一条消息。 – Daniel