代码之家  ›  专栏  ›  技术社区  ›  Lenciel

va_arg()的问题

  •  0
  • Lenciel  · 技术社区  · 15 年前

    我想用这种方式来获取带有变量参数的函数:

    static void configElement(U32 localFaultId,
                              char* name,
                              U32  report,
                              U32  localId,
                              U32  detectTime,
                              U32  ceaseTime,...)
    {
      U32 i = 0;
      U32 tmpNo = 0;
      va_list ap;
    
      if (nofFaults >= MAX_NOF_LOCAL_FAULTS)
      {
        //something here
        return;
      }
      else
      {
    
        faultList[nofFaults].ceaseTime  = ceaseTime;
    
        va_start(ap, ceaseTime);
        tmpNo = va_arg(ap, U32);
        while ((tmpNo!= END_MARK) && (i < MAX_NOF_DEPEND))
        {
          faultList[nofFaults].dependList[i++].faultNo = tmpNo;
        }
    
    
        faultList[nofFaults].dependList[i].faultNo = END_MARK;
        /* Finish by increment nofFaults parameter */
        va_end(ap);
        nofFaults++;
      }
    }
    

    但是,在编译此代码时收到错误消息:

    fault_manager.cc:3344: error: expected primary-expression before ',' token
    fault_manager.cc:3387: error: expected primary-expression before 'U32'
    fault_manager.cc:3387: error: expected `)' before 'U32'
    fault_manager.cc:3387: error: expected `)' before ';' token
    fault_manager.cc:3387: error: expected `)' before ';' token
    

    我不知道这里出了什么问题。我的平台是Windows,我使用的是Cygwin+Eclipse(CDT)。GCC版本为4.1.1。

    任何想法都会受到赞赏的!

    1 回复  |  直到 15 年前
        1
  •  4
  •   PeterK    15 年前

    看起来编译器不知道u32是什么。是否包括所有必要的标题?