mex 编译 c 文件报错

在编译Hoiem的Recovering Occlusion Boundaries项目时,遇到mex编译C文件报错。问题在于C编译器不允许在函数内部声明变量。将变量声明移出函数解决了问题,但仍有疑问:为何在for循环内声明变量可以?期待对C语言规则了解的人解答。使用的是msvc2010编译器,不清楚gcc是否能直接编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在编译的Hoiem的一个项目, 就是Recovering Occlusion Boundaries。 不得不说, 这家伙是在是太不friendly了,不放源代码,只放编译好的mex文件。而 他放的代码都是0607年的, 那时候matlab版本很低。而且gcc也只有可怜的3.3,现在都4.8了! 所以用他的代码, 会让你无比纠结。


不过还是调试成功了。 但在调试时遇到一个很有意思的问题: mex编译c文件报错。


c文件如下, treevalc.c

#include "mex.h"
#include <stdlib.h>
#include <stdio.h>
/** 
 * Return the decision tree node corresponding to the given value set
 *
 * var[n]: the attribute ids for node n
 * cut[n]: the threshold value for node n
 * left_child[n]: the node id of the left child of node n, 0 if node n is terminal
 * right_child[n]: the node id of the right child of node n, 0 if node n is terminal
 * ncatsplit[c]: the number of values resulting in a left branch
 * catsplit[c]: the values that would result in a left branch
 * attributes: the attribute (variable) values for each feature
 **/
void
treevalc(int* var, double* cut, int* left_child, int* right_child, 
	 int* ncatsplit, double** catsplit, 
	 double* attributes,
	 int* node_id) {
 
  int currnode = 0;

  int nextnode;
  int currvar;
  double currval;
  int cid, v;
  int numvals;
  double* vals;

  /*  printf("init nodes: %d  %d  \n", left_child[currnode], right_child[currnode]); */

  /* until reached terminal node */
  while ((left_child[currnode] != 0) && (right_child[currnode] != 0)) {
    
    /*printf("currnode: %d\n", currnode);*/

    nextnode = -1;
    
    currvar = abs(var[currnode])-1;
    currval = attributes[currvar];
    
    /* decision based on thresholded float value */
    if (var[cu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值