linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: "Uecker, Martin" <Martin.Uecker@med.uni-goettingen.de>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: detecting integer constant expressions in macros
Date: Tue, 20 Mar 2018 17:30:38 -0700	[thread overview]
Message-ID: <CA+55aFyfW7kA_72vNifyxBV7gc_fkKjVC3j1WBJzx1R3GpApOQ@mail.gmail.com> (raw)
In-Reply-To: <1521591040.508.2.camel@med.uni-goettingen.de>

On Tue, Mar 20, 2018 at 5:10 PM, Uecker, Martin
<Martin.Uecker@med.uni-goettingen.de> 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

  reply	other threads:[~2018-03-21  0:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-20 22:13 detecting integer constant expressions in macros Uecker, Martin
2018-03-20 23:07 ` Uecker, Martin
2018-03-20 23:09   ` Linus Torvalds
2018-03-20 23:08 ` Linus Torvalds
2018-03-21  0:10   ` Uecker, Martin
2018-03-21  0:30     ` Linus Torvalds [this message]
2018-03-21  9:51       ` Uecker, Martin
2018-03-21 10:22         ` Uecker, Martin
2018-03-21 10:35           ` David Laight
2018-03-21 21:10   ` Rasmus Villemoes
2018-03-21 22:27     ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+55aFyfW7kA_72vNifyxBV7gc_fkKjVC3j1WBJzx1R3GpApOQ@mail.gmail.com \
    --to=torvalds@linux-foundation.org \
    --cc=Martin.Uecker@med.uni-goettingen.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).