From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763735AbdEWMDG (ORCPT ); Tue, 23 May 2017 08:03:06 -0400 Received: from smtp81.iad3a.emailsrvr.com ([173.203.187.81]:35547 "EHLO smtp81.iad3a.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763718AbdEWMDC (ORCPT ); Tue, 23 May 2017 08:03:02 -0400 X-Auth-ID: siepeng@mev.co.uk X-Sender-Id: siepeng@mev.co.uk Subject: Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of() To: Peter Zijlstra References: <20170522150340.15461-1-abbotti@mev.co.uk> <139f0546-9b0a-d119-6b96-a9b35559be4b@mev.co.uk> <20170523112415.nmbazvqmlhy343f2@hirez.programming.kicks-ass.net> Cc: Michal Nazarewicz , linux-kernel@vger.kernel.org, Andrew Morton , Hidehiro Kawai , Borislav Petkov , Rasmus Villemoes , Johannes Berg , Alexander Potapenko From: Ian Abbott Message-ID: Date: Tue, 23 May 2017 13:02:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170523112415.nmbazvqmlhy343f2@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/05/17 12:24, Peter Zijlstra wrote: > On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote: > >>> #define container_of(ptr, type, member) ( \ >>> _Static_assert(__builtin_types_compatible_p( \ >>> typeof(*ptr), typeof( ((type *)0)->member )), "WUT"), \ >>> ((type *)((char *)(ptr) - offsetof(type, member))); \ >>> ) >> >> It's a fine suggestion (if more parentheses are added), but _Static_assert >> is a C11 feature, and I thought the kernel was using gnu89 (unless it's been >> updated since). > > We have BUILD_BUG_ON() that should be similar in functionality. Yes, I think BUILD_BUG_ON_ZERO() will be better in this case to avoid some baggage. Also, __same_type() can be used for type checking. -- -=( Ian Abbott @ MEV Ltd. E-mail: )=- -=( Web: http://www.mev.co.uk/ )=-