如何一次从unsigned char
缓冲区读取3个字节(作为一个整数)?
uint_24 p = *(unsigned char[3])buffer;
上面的代码不起作用。
最佳答案
如果可以将缓冲区重新定义为并集的一部分,并且整数endian符合预期:
union {
unsigned char buffer[3];
uint_24 p;
} x;
foo(x.buffer); // somehow data is loaded into x.buffer
uint_24 destination = x.p; // read: let compiler do the work
通过合并,可以满足对齐问题。