[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wgBM7Swi7wmvi0M+sBFjzn-vEv1KzgM-hbJ4h3J3BR+UA@mail.gmail.com>
Date: Thu, 26 Oct 2023 06:54:07 -1000
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: David Laight <David.Laight@...lab.com>
Cc: Vasily Gorbik <gor@...ux.ibm.com>,
Sebastian Reichel <sebastian.reichel@...labora.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Michael Turquette <mturquette@...libre.com>,
Stephen Boyd <sboyd@...nel.org>,
"linux-clk@...r.kernel.org" <linux-clk@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Niklas Schnelle <schnelle@...ux.ibm.com>,
"kernel@...labora.com" <kernel@...labora.com>
Subject: Re: [PATCH v4 1/3] math.h: add DIV_ROUND_UP_NO_OVERFLOW
On Wed, 25 Oct 2023 at 22:57, David Laight <David.Laight@...lab.com> wrote:
>
> Doesn't that version end up calling inline functions?
> So won't be usable in static initialisers - the same as statement functions.
David, please either read what I write, or actually test things out,
instead of just adding noise.
It is not a problem to have a _Generic() - or a
__builtin_chooise_expr() - that has an inline function that doesn't
get used. The compiler will remove it.
The problem is literally that you can't use "__auto_type", because
*STATEMENT EXPRESSIONS* do not work outside of function definitions,
because gcc won't even *parse* them, and just says
error: braced-group within expression allowed only inside a function
exactly like I explained in the comment of the patch that does the _Generic().
Which is why my solution ended up using those inline functions, and
splitting manually by type, instead of an expression statement and
__auto_type.
Whether you then split into different expressions with _Generic() or
by using __builtin_choose_expr() is irrelevant, although once you do
"split by type", _Generic() ends up being much more convenient because
that's what it's designed for (and you don't end up trying to figure
out the size with sizeof() and typeof tricks).
Linus
Powered by blists - more mailing lists