错误:初始化表达式列表被视为复合表达式

时间:2013-08-29 14:22:42

标签: c++

我无法找到解决此错误的方法。我已经尝试了所有我能想到的内容并查看了网络上的一些示例。但是我还是卡住了!

由于

错误:初始化表达式列表被视为复合表达式

unsigned char mbuffer[16];

int bcd_encode(32768UL, &mbuffer[0], 4);   <---- error is on this line



-------------------------------------------------

/* Encode the input number into BCD into the output buffer, of
 * the specified length.  The BCD encoded number is right-justified
 * in the field.  Return the number of digits converted, or -1 if the
 * buffer was not big enough for the whole conversion.
 */
int bcd_encode(unsigned long number, unsigned char *cbuffer, int length)
{
  unsigned char *p;
  unsigned char n, m, bval, digit;

   n = 0;     /* nibble count */
   m = 0;     /* converted digit count */
   bval = 0;  /* the bcd encoded value */


   /* Start from the righthand end of the buffer and work
    * backwards
    */
   p = cbuffer + length - 1;
   while (p >= cbuffer) {

       if (number != 0) {
          digit = number % 10;
          number = number / 10;
          m++;
       } else
          digit = 0;

       /* If we have an odd-numbered digit position
        * then save the byte and move to the next buffer
        * position.  Otherwise go convert another digit
        */
       if (n & 1) {
          bval |= digit << 4;
          *p-- = bval;
          bval = 0;
       } else
          bval = digit;

       n++;
   }

   /* If number is not zero, then we have run out of room
    * and the conversion didn't fit.  Return -1;
    */
   if (number)
      return(-1);

   /* return the number of converted digits
    */
   return(m);
}

2 个答案:

答案 0 :(得分:0)

您在通话前遇到孤独的int,这无效。

应该是:

const int numDigits = bcd_encode(32768UL, &mbuffer[0], 4);

答案 1 :(得分:0)

为什么函数原型中有值?

应该是:

int bcd_encode(unsigned long number, unsigned char *cbuffer, int length); 

或者,如果您正在尝试调用该函数,请执行unwind说明并从头开始删除