Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757419AbZDPSdk (ORCPT ); Thu, 16 Apr 2009 14:33:40 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756220AbZDPSda (ORCPT ); Thu, 16 Apr 2009 14:33:30 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:33324 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753438AbZDPSda (ORCPT ); Thu, 16 Apr 2009 14:33:30 -0400 Date: Thu, 16 Apr 2009 19:33:27 +0100 From: Al Viro To: H Hartley Sweeten Cc: Vegard Nossum , linux-kernel@vger.kernel.org Subject: Re: [PATCH] block/genhd.c: fix sparse warning Message-ID: <20090416183327.GC26366@ZenIV.linux.org.uk> References: <19f34abd0904152146l3db9961bt3b52f224abc8d960@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 920 Lines: 24 On Thu, Apr 16, 2009 at 02:03:39PM -0400, H Hartley Sweeten wrote: > Maybe something like: > > #define container_of(ptr, type, member) ({ \ > const typeof( ((type *)0)->member ) *__m_##ptr = (ptr); \ > (type *)( (char *)__m_##ptr - offsetof(type,member) );}) > > I don't know if that actually works. ;-) _Think_ of it. Will do bleeding wonders if you say container_of(f(), struct foo, bar) won't it? No, the real solution for that is this: #define container_of(ptr, type, member) (type *) \ ((char *)(1 ? (ptr) : ((const typeof(((type *)0)->member) *)(ptr))) \ - offsetof(type, member)) Same amount of typechecking, no local variables, no ({ }) uses. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/