1

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

谢谢

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

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);
}
4

2 回答 2

1

为什么函数原型中有值?

应该:

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

或者,如果您尝试调用该函数,请按照 unwind 所说的操作并从头开始删除 int

于 2013-08-29T14:25:19.810 回答
0

打电话前你感到很孤独int,那是无效的。

它应该是:

const int numDigits = bcd_encode(32768UL, &mbuffer[0], 4);
于 2013-08-29T14:24:39.330 回答