我學習的書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