[cfe-dev] 'struct' member alignment query

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Thu Feb 9 10:02:49 PST 2017


The "right" way to get this effect is to use __attribute__((packed)) on the
field.

On 9 Feb 2017 9:33 am, "Martin J. O'Riordan via cfe-dev" <
cfe-dev at lists.llvm.org> wrote:

Wow!  Thanks for the response, that worked perfectly.

I never would have expected that the indirect 'typedef' approach would
behave any differently to the more direct annotation!  I feel that this is
probably an unintended GCC behaviour/bug, though CLang is 100% right to
maintain compatibility with GCC.

But it solved my problem, thanks very much,

        MartinO

-----Original Message-----
From: Tim Northover [mailto:t.p.northover at gmail.com]
Sent: 09 February 2017 15:08
To: Martin J. O'Riordan <Martin.ORiordan at movidius.com>
Cc: cfe-dev <cfe-dev at lists.llvm.org>
Subject: Re: [cfe-dev] 'struct' member alignment query

On 9 February 2017 at 02:56, Martin J. O'Riordan via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> Is this expected behaviour in 'clang', and if so, is there another way
> I can coerce the 'struct' member 'alignCheck2' onto another less
> constrained alignment boundary?

It's expected, but I think only because of GCC compatibility because it's
really not obvious behaviour. The workaround, which still mystifies me, is
to go via a typedef:

typedef AlignCheck_t __attribute__((aligned(1))) UnAlignCheck_t;

then you can put that in the struct and it'll be laid out without any
padding.

Tim.

_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170209/76f7772c/attachment.html>


More information about the cfe-dev mailing list