gpt4 book ai didi

c - 如何读取3个字节的整数?

转载 作者:行者123 更新时间:2023-12-02 03:27:38 25 4
gpt4 key购买 nike

如何一次从 unsigned char 缓冲区中读取 3 个字节(作为整数)?

uint_24 p = *(unsigned char[3])buffer;

上面的代码不起作用。

最佳答案

如果可以将缓冲区重新定义为 union 的一部分并且整数字节序符合预期:

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

通过加入 union ,对齐问题得到满足。

关于c - 如何读取3个字节的整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29577831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com