[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Re: [PATCH 07/17] block/vvfat.c: fix warnings with _FOR

From: Jamie Lokier
Subject: Re: [Qemu-devel] Re: [PATCH 07/17] block/vvfat.c: fix warnings with _FORTIFY_SOURCE
Date: Wed, 20 Jan 2010 16:16:07 +0000
User-agent: Mutt/1.5.13 (2006-08-11)

Kirill A. Shutemov wrote:
> On Wed, Jan 20, 2010 at 3:03 PM, Markus Armbruster <address@hidden> wrote:
> > "Kirill A. Shutemov" <address@hidden> writes:
> >> No, compiler can't add anything between. 'char' is always byte-aligned.
> >
> > You got some reading to do then.
> Do you want to say that it's not true? Could you provide an example
> when 'char' isn't byte-aligned?

I have no example, but that doesn't mean there is no architecture, ABI
or host OS where it happens.  Architectures can be surprising.

It's very easy to make assumptions which break on some architecture
you've never tested on.

Take this code:

struct part1 {
        char c[5];

struct part2 {
        char c[3];

struct all {
        struct part1 p1;
        struct part2 p2;

What do you think the size is on ARM?  Hint: not 8 when using GCC < 4,
but it is 8 when using current GCC and the later ARM ABI.

This broke some data parsing application when it was ported from x86
to ARM, because of a wrong assumption about structure layout that
works on nearly all architectures and passed all testing prior to the port.

-- Jamie

reply via email to

[Prev in Thread] Current Thread [Next in Thread]