gpt4 book ai didi

c++ - 错误 : initializer expression list treated as compound expression

转载 作者:太空宇宙 更新时间:2023-11-04 14:02:38 27 4
gpt4 key购买 nike

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

谢谢

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

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

最佳答案

为什么函数原型(prototype)中有值?

应该是:

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

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

关于c++ - 错误 : initializer expression list treated as compound expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18513580/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com