问题描述
最近我遇到了一个奇怪的错误/功能。 在 MATLAB 中使用 C Matrix API 开发 C 函数我犯了一个错误,传递的参数多于函数声明的参数,并且编译器没有引发相关错误。
使用 Matlab C 矩阵 API 的一个小例子 - mex_with_bug.c:
#include "mex.h"
int function_which_declares_one_input(int a) {
return a;
}
void mexFunction(int hlhs,mxArray* plhs[],int nrhs,const mxArray* prhs[]) {
// expected usage
function_which_declares_one_input(1);
// totally not expected use cases
function_which_declares_one_input(1,2);
function_which_declares_one_input(1,2,3);
function_which_declares_one_input(1,3,'a');
}
Matlab 编译命令:
mex -v COMPFLAGS="$COMPFLAGS -Wall" mex_with_bug.c
只给出警告,没有错误:
...
mex_with_bug.c(13): warning C4020: "function_which_declares_one_input": too many real parameters
mex_with_bug.c(14): warning C4020: "function_which_declares_one_input": too many real parameters
mex_with_bug.c(15): warning C4020: "function_which_declares_one_input": too many real parameters
...
并且调用函数 mex_with_bug
工作正常:
>> mex_with_bug()
>>
为什么没有出现错误?为什么 C 需要这个“特性”?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)