From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936875AbdEWLYe (ORCPT ); Tue, 23 May 2017 07:24:34 -0400 Received: from merlin.infradead.org ([205.233.59.134]:37864 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752433AbdEWLYd (ORCPT ); Tue, 23 May 2017 07:24:33 -0400 Date: Tue, 23 May 2017 13:24:15 +0200 From: Peter Zijlstra To: Ian Abbott Cc: Michal Nazarewicz , linux-kernel@vger.kernel.org, Andrew Morton , Hidehiro Kawai , Borislav Petkov , Rasmus Villemoes , Johannes Berg , Alexander Potapenko Subject: Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of() Message-ID: <20170523112415.nmbazvqmlhy343f2@hirez.programming.kicks-ass.net> References: <20170522150340.15461-1-abbotti@mev.co.uk> <139f0546-9b0a-d119-6b96-a9b35559be4b@mev.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <139f0546-9b0a-d119-6b96-a9b35559be4b@mev.co.uk> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.