[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150309154538.GA21578@gmail.com>
Date: Mon, 9 Mar 2015 16:45:38 +0100
From: Ingo Molnar <mingo@...nel.org>
To: Andy Lutomirski <luto@...capital.net>
Cc: Denys Vlasenko <vda.linux@...glemail.com>,
Denys Vlasenko <dvlasenk@...hat.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Steven Rostedt <rostedt@...dmis.org>,
Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>, Oleg Nesterov <oleg@...hat.com>,
Frederic Weisbecker <fweisbec@...il.com>,
Alexei Starovoitov <ast@...mgrid.com>,
Will Drewry <wad@...omium.org>,
Kees Cook <keescook@...omium.org>, X86 ML <x86@...nel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 1/2] move offsetofend() from vfio.h to stddef.h
* Andy Lutomirski <luto@...capital.net> wrote:
> > So I might be missing something, but what generic uses does it
> > have, beyond structures that have some rare size related
> > weirdness, such as alignment attributes? In 99% of the cases:
> >
> > sizeof(struct) == offsetofend(struct, last_member)
> >
> > right?
>
> struct foo {
> u64 a;
> char b;
> };
>
> sizeof(struct foo) will be 16, but offsetofend(struct foo, b) will be
> 9 on most platforms, right?
I knew I missed something obvious :-)
Let me attempt to get it right:
When the next byte after the last member of a structure is not aligned
to the largest alignment requirement of any structure member, then the
structure grows (is padded) and offsetofend() < sizeof().
'packed' or 'aligned' attributes will modify the largest alignment
requirement value so they are a common but not only mechanism for this
to be the case.
Thanks,
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists