我试图找出如何在appSignatureBytes
数组中拥有两个字节commentExtension
数组,以便代码可以保持独立;会有办法做到这一点吗? appSignatureBytes[0-sizeof(appSignatureBytes)]
以便在编译时插入所有元素?
const uint8_t appSignatureBytes [] = { 0x48, 0x69 };
const uint8_t commentBytesSizeByte = sizeof(appSignatureBytes);
const uint8_t commentExtension [] = { extensionIntroducerByte,
commentLabelByte, commentBytesSizeByte, appSignatureBytes[0-sizeof(appSignatureBytes)],
blockTerminatorByte };
答案 0 :(得分:4)
如果在编译时确实需要它,可以使用共享预处理器定义:
#define MAGIC_BYTES 0x48, 0x69
const uint8_t appSignatureBytes[] = { MAGIC_BYTES };
const uint8_t commentBytesSizeByte = sizeof appSignatureBytes;
const uint8_t commentExtension[] =
{
extensionIntroducerByte,
commentLabelByte,
commentBytesSizeByte,
MAGIC_BYTES,
blockTerminatorByte
};