gpt4 book ai didi

c - ARM 上的字对齐?

转载 作者:太空宇宙 更新时间:2023-11-04 04:03:17 25 4
gpt4 key购买 nike

如何避免在以下代码中出现编译器警告(警告:转换会增加目标类型所需的对齐方式)?

static int fill_color24 (VisVideo *video, VisColor *color)
{
int x, y;
uint32_t *buf;
uint8_t *rbuf = visual_video_get_pixels (video);
uint8_t *buf8;

int32_t cola =
(color->b << 24) |
(color->g << 16) |
(color->r << 8) |
(color->b);
int32_t colb =
(color->g << 24) |
(color->r << 16) |
(color->b << 8) |
(color->g);
int32_t colc =
(color->r << 24) |
(color->b << 16) |
(color->g << 8) |
(color->r);

for (y = 0; y < video->height; y++) {
buf = (uint32_t *) rbuf; // warning is for this line

for (x = video->width; x >= video->bpp; x -= video->bpp) {
*(buf++) = cola;
*(buf++) = colb;
*(buf++) = colc;
}

buf8 = (uint8_t *) buf;
*(buf8++) = color->b;
*(buf8++) = color->g;
*(buf8++) = color->r;


rbuf += video->pitch;
}

return VISUAL_OK;
}

最佳答案

我不确定你能做到。该函数可能会返回未对齐的颜色数组。你不能做任何事情来从那里读取单词。您必须按组件 (uint8_t) 读取颜色,然后通过添加和移动从这些组件构建 uint32_t。

关于c - ARM 上的字对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9306725/

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