From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932225AbXCJUgo (ORCPT ); Sat, 10 Mar 2007 15:36:44 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932223AbXCJUgo (ORCPT ); Sat, 10 Mar 2007 15:36:44 -0500 Received: from mail1.sea5.speakeasy.net ([69.17.117.3]:43443 "EHLO mail1.sea5.speakeasy.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932217AbXCJUgn (ORCPT ); Sat, 10 Mar 2007 15:36:43 -0500 Date: Sat, 10 Mar 2007 12:36:41 -0800 (PST) From: Trent Piepho X-X-Sender: xyzzy@shell4.speakeasy.net To: Linus Torvalds cc: Christoph Hellwig , Rusty Russell , lkml - Kernel Mailing List , Andrew Morton Subject: Re: [PATCH] Use more gcc extensions in the Linux headers In-Reply-To: Message-ID: References: <1173419792.32234.131.camel@localhost.localdomain> <20070309065055.GA18056@pazke.donpac.ru> <20070309075308.GE8798@infradead.org> <20070309090218.GB18056@pazke.donpac.ru> <20070309090510.GA24908@infradead.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 9 Mar 2007, Linus Torvalds wrote: > On Fri, 9 Mar 2007, Christoph Hellwig wrote: > Well, since Rusty's macro was hoddible *anyway*, I don't think I'd apply > it as-is. Breaking icc for something that ugly and not-very-important > simply makes no sense. > > There are better ways to do this. > > For one, you could (and should!) abstract these kinds of things out, > rather than put them in another macro that really does something totally > different. Then, the macro could have become > > #define ARRAY_SIZE (sizeof_expression + 0*error_if_not_array) /* Error if X is a pointer, 0 otherwise */ #define ERROR_IF_POINTER(x) \ sizeof(int[-__builtin_types_compatible_p(typeof(x), typeof(&x[0]))]) /* Warning (div by zero) if x is a pointer, 0 otherwise */ #define WARN_IF_POINTER(x) \ (0/!__builtin_types_compatible_p(typeof(x), typeof(&x[0]))) The gcc docs say __builtin_types_compatible_p returns 1 or 0, so the !! isn't necessary. And my gcc at least returns 0 for sizeof(int[0]).