我正在使用 micropython 中的 C 模块...如果我将字节数组传递给函数,则只有前 8 个字节会成功(根据 sizeof)。我还必须发送长度,然后复制它以访问函数中的所有内容。
static void printSomeBytes(char *description, byte *bytes)
{
printf("\r\n%s: ", description);
for (int i = 0; i < sizeof(bytes); ++i )
{
printf("%02X", bytes[i]);
}
}
static void printAllBytes(char *description, byte *bytes, int length)
{
byte copy[length];
memcpy(copy, bytes, length);
printf("\r\n%s: ", description);
for (int i = 0; i < sizeof(copy); ++i )
{
printf("%02X", copy[i]);
}
// this also works without making a copy
//for (int i = 0; i < length; ++i )
//{
// printf("%02X", bytes[i]);
//}
}
byte Kifd[] = { 0x0B, 0x79, 0x52, 0x40, 0xCB, 0x70, 0x49, 0xB0, 0x1C, 0x19, 0xB3, 0x3E, 0x32, 0x80, 0x4F, 0x0B};
printSomeBytes("Kifd", kifd); // prints "Kifd: 0B795240CB7049B0"
printAllBytes("Kifd", kifd, sizeof(kifd)); // prints "Kifd: 0B795240CB7049B01C19B33E32804F0B"
我在做什么错/有没有更好的方法将指向字节数组的指针发送到函数?