数组下标的无效类型“unsigned char [int]”[关闭]
Posted
技术标签:
【中文标题】数组下标的无效类型“unsigned char [int]”[关闭]【英文标题】:invalid types ‘unsigned char[int]’ for array subscript [closed] 【发布时间】:2014-07-09 15:41:33 【问题描述】:我正在尝试使用数据字节创建 CRC,并且我已经编写了这个函数:
u16 crcGenerate(unsigned char bytes, int len)
u16 crc = 0;
for (int i = 0; i < len; i++)
crc = crc16__computeByteAnsi(crc, bytes[i]);
return crc;
每当调用此函数时,我都会不断收到上述错误,我不太确定如何修复它,甚至不知道出了什么问题。
为避免使这个问题变得臃肿,我已经包含了引用的其他主要 .h 和 .cpp 文件。
This is the Command header file (cmgCOM.h)
This is where the CRCs are computed (crc16.cpp)
This is the primary Command file (cmgCOM.cpp)
我非常感谢我能得到的任何帮助;如果需要提供更多信息,请告诉我。我对 C/C++ 不是很熟悉,也不知道是什么导致了这个问题。
谢谢。
【问题讨论】:
您缺少*
。你想要unsigned char *bytes
。
【参考方案1】:
我认为您希望 bytes
成为一个 unsigned char 数组,但您只将其标记为单个 unsigned char 值。
u16 crcGenerate(unsigned char bytes[], int len)
【讨论】:
以上是关于数组下标的无效类型“unsigned char [int]”[关闭]的主要内容,如果未能解决你的问题,请参考以下文章
如何将C++中string类型的字符串赋给unsigned char数组
C++怎么将 CString 转换成 unsigned char 的数组
从“const char*”到“unsigned char*”的无效转换