VC工程里,加入了C代码,比如A函数体在一个C文件里,其声明是在一个.h文件下,另一个C的B函数调用A函数,包含该.h文件,但是,该函数却不执行,编译连接都没错。

解决方案 »

  1.   

    函数体在A.c:
    ST_RET sx_parseExx_mt (ST_CHAR *fileName, ST_INT numItems, 
       SX_ELEMENT *itemTbl, ST_VOID *usr,
       ST_RET (*u_sx_el_start_fun) (SX_DEC_CTRL *sxDecCtrl, ST_CHAR *tag),
       ST_RET (*u_sx_el_end_fun) (SX_DEC_CTRL *sxDecCtrl, ST_CHAR *tag))
    {
    ST_RET rc;
    ST_LONG fileSize;
    ST_LONG bytesRead;
    ST_CHAR *cfgData;
    struct stat buf;
    int result;
    FILE *fp;

    /* Get the size of the file */
    fp = fopen (fileName, "r");
    if (fp == NULL)
        {
    SXLOG_FLOW2 ("XML File (%s) Open Error (errno=%d)", fileName, errno);
    printf ("XML File (%s) Open Error (errno=%d)\n", fileName, errno);
    return (SX_FILE_NOT_FOUND);
        }
    result = fstat (fileno (fp), &buf);
    if (result != 0)
    return (SD_FAILURE);

    /* Allocate a buffer and read all into memory */
    fileSize = buf.st_size;
    cfgData = (ST_CHAR *) chk_malloc (fileSize);

    bytesRead = fread (cfgData, 1, fileSize, fp);
    fclose (fp);
    if (bytesRead <= 0)
        {
    chk_free (cfgData);
    SXLOG_FLOW1 ("Error: Could not read from '%s'", fileName);
    return (SX_FILE_NOT_FOUND);
        }

    rc = sx_parse_mt (bytesRead, cfgData, numItems, itemTbl, usr, 
           u_sx_el_start_fun, u_sx_el_end_fun); 
    if (rc != SD_SUCCESS)
        {
    SXLOG_FLOW1 ("ERROR: parsing failed, return code: '%d'", rc);
        }

    chk_free (cfgData);
    return (rc);
    }在B.h文件下声明:
    ST_RET sx_parseExx_mt (ST_CHAR *fileName, ST_INT numItems, 
    SX_ELEMENT *itemTbl, ST_VOID *usr,
    ST_RET (*u_sx_el_start_fun) (SX_DEC_CTRL *sxDecCtrl, ST_CHAR *tag),
    ST_RET (*u_sx_el_end_fun) (SX_DEC_CTRL *sxDecCtrl, ST_CHAR *tag));
    在C.c下调用:
      rc = sx_parseExx_mt (logFileName, 0, NULL, &logCfgxCtrl, _logcfg_data_start, _logcfg_data_end);
    但是调试时根本不进入该函数,直接跳出。
      

  2.   

    额。。大哥。。光有声明,没有实现的.cpp文件怎么调用?你是有的动态库么?
      

  3.   

    说明下:在C.c下包含了B.h文件的。
      

  4.   

    不太明白调用C文件的问题,如果有.h声明的话,那么他与函数实现的文件肯定得是一个类吧?
    你在C文件里面也加上B.h试试。