另一个uint8_t数组中的uint8_t数组可能吗?

时间:2015-04-24 02:51:38

标签: objective-c c pointers

我试图找出如何在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 };

1 个答案:

答案 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
};