【问题标题】:word alignment on ARM?ARM上的字对齐?
【发布时间】:2012-02-16 06:45:27
【问题描述】:

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

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

【问题讨论】:

    标签: c arm memory-alignment


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-09-28
      • 1970-01-01
      • 2013-04-17
      • 2021-12-05
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 1970-01-01
      相关资源
      最近更新 更多