From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751521AbeCUAal (ORCPT ); Tue, 20 Mar 2018 20:30:41 -0400 Received: from mail-io0-f179.google.com ([209.85.223.179]:45254 "EHLO mail-io0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751396AbeCUAaj (ORCPT ); Tue, 20 Mar 2018 20:30:39 -0400 X-Google-Smtp-Source: AG47ELvACKOgvzlNoHdb+f7KejRP0nHLrRz08To6aLBq+qYytKOgw5/dTsoFoBXyYjSv4C4YcHtTLQHwi40Ny6gBe3w= MIME-Version: 1.0 In-Reply-To: <1521591040.508.2.camel@med.uni-goettingen.de> References: <1521584015.31174.3.camel@med.uni-goettingen.de> <1521591040.508.2.camel@med.uni-goettingen.de> From: Linus Torvalds Date: Tue, 20 Mar 2018 17:30:38 -0700 X-Google-Sender-Auth: cLLzlYIhB1jKascG09zi2uGfjPY Message-ID: Subject: Re: detecting integer constant expressions in macros To: "Uecker, Martin" Cc: "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 20, 2018 at 5:10 PM, Uecker, Martin wrote: > >> >> So I see two issues: >> >> - "sizeof(*(void *)1)" is not necessalily well-defined. For gcc it >> is >> 1. But it could cause warnings. > > It is a documented extension which enables pointer arithmetic > on void pointers, so I am sure neither gcc nor > clang has any problem with it. Well, so sparse does the whole "void pointer arithmetic" thing too, but sparse actually complains about use of sizeof(void). We could remove that warning, though. But: > But one could also use __builtin_types_compatible_p instead. That might be the right approach, even if I like how it only used standard C (although _disgusting_ standard C) without it apart from the small issue of sizeof(void) So something like #define __is_constant(a) \ __builtin_types_compatible_p(int *, typeof(1 ? ((void*)((a) * 0l)) : (int*)1 ) ) if I counted the parentheses right.. Linus