Hi Bruno,

On Tue, Jun 03, 2025 at 10:38:22AM +0200, Bruno Haible wrote:
> Alejandro Colomar wrote:
> > BTW, there's 3 more operators in the oven, which I expect will be
> > approved in August for C2y: _Widthof, _Minof, and _Maxof.
> > <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3518.txt>
> > The feedback from the C Committee has been good so far.  I don't have a
> > header in mind for those operators, but I might add it as <stdwidth.h>
> > if the committee wants one.
> 
> Given that <stdint.h> already defines various *_WIDTH, *_MIN, *_MAX macros,
> it would seem logical to stuff _Widthof, _Minof, _Maxof into <stdint.h>
> if they are not to be compiler built-ins. (They don't need to be compiler
> built-ins because they can be implemented portably, see 
> gnulib/lib/intprops.h).

They will be compiler builtins, because of _BitInt.

        alx@devuan:~/src/gnu/gnulib/master$ grepc TYPE_WIDTH lib/intprops.h 
        lib/intprops.h:#define TYPE_WIDTH(t) _GL_TYPE_WIDTH (t)
        alx@devuan:~/src/gnu/gnulib/master$ grepc _GL_TYPE_WIDTH .
        ./lib/intprops-internal.h:#define _GL_TYPE_WIDTH(t) (sizeof (t) * 
CHAR_BIT)

The use of CHAR_BIT makes it always return a multiple of 8, but things
like _BitInt(7) don't fit in that model.  We need a true operator that
makes 7 == _Widthof(_BitInt(7)).

About using <stdint.h> for the widthof macro, it might be possible.
We'll probably discuss that option during the meeting.  A concern that
I expect is that we'd be introducing a macro name already in use, so it
would conflict with existing code that uses it.  widthof() isn't
problematic, as it's only used in two projects, and with compatible
semantics.

<https://codesearch.debian.net/search?q=define.*%5Cbwidthof%5Cb&literal=0>

However, minof() and maxof() are in use, and with
incompatible semantics, so we clearly need a new header file.

<https://codesearch.debian.net/search?q=define.*%5Cbminof%5Cb&literal=0>
<https://codesearch.debian.net/search?q=define.*%5Cbmaxof%5Cb&literal=0>

BTW, clisp is one such place.  Would you mind renaming clisp's minof()
to just min()?



Have a lovely day!
Alex

-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature

Reply via email to