From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754013AbbCIPpr (ORCPT ); Mon, 9 Mar 2015 11:45:47 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:45226 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752754AbbCIPpn (ORCPT ); Mon, 9 Mar 2015 11:45:43 -0400 Date: Mon, 9 Mar 2015 16:45:38 +0100 From: Ingo Molnar To: Andy Lutomirski Cc: Denys Vlasenko , Denys Vlasenko , Linus Torvalds , Steven Rostedt , Borislav Petkov , "H. Peter Anvin" , Oleg Nesterov , Frederic Weisbecker , Alexei Starovoitov , Will Drewry , Kees Cook , X86 ML , Linux Kernel Mailing List Subject: Re: [PATCH 1/2] move offsetofend() from vfio.h to stddef.h Message-ID: <20150309154538.GA21578@gmail.com> References: <1425912738-559-1-git-send-email-dvlasenk@redhat.com> <20150309145844.GA19511@gmail.com> <20150309152822.GA21219@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Andy Lutomirski 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