public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: Paul Eggert <eggert@cs.ucla.edu>,
	libc-alpha@sourceware.org, Florian Weimer <fweimer@redhat.com>,
	JeanHeyd Meneide <wg14@soasis.org>
Subject: Re: [PATCH] inttypes.h: imaxabs(3): Implement as a macro
Date: Wed, 14 Sep 2022 01:43:09 +0200	[thread overview]
Message-ID: <43da981a-5727-d521-9aa2-a56aa9cd2f53@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2209132248120.3106583@digraph.polyomino.org.uk>


[-- Attachment #1.1: Type: text/plain, Size: 3769 bytes --]

Hi Joseph,

On 9/14/22 00:56, Joseph Myers wrote:
> On Tue, 13 Sep 2022, Alejandro Colomar wrote:
> 
>> I don't understand the process by which gcc expands builtins.  How does
>> exactly the suggested macro interfere with it?  Is it because of the macro?
>> Or because of _Generic()?
> 
> My point is that you already have to go out of your way to get a link-time
> reference to imaxabs - it will almost always have been expanded inline
> instead.  Given that, your patch is adding extra complexity to address an
> issue that doesn't actually exist.

Ahh, now I understand.  So, kind of the situation with bzero(3) which is 
implemented in the compiler, and glibc doesn't support it because the 
compiler always transforms it to memcpy(3).

Then, if there are still any references, glibc still needs to fix that, 
or if there are no references, glibc could just remove the function 
completely.

However, imaxabs(3) was just the starting point, because it happened to 
be the function I chose to use at random.  Other functions using the 
type may not be so commonly inlined.

> 
>> That is a workaround to the type being broken.  The type can't widen, due to
>> ABI issues; for some time, the compiler provided __int128 as a limbo extension
>> that wouldn't be covered by intmax_t, and later ISO C just acknowledged the
>> fact and reworded the definition of intmax_t to be less of "the widest type"
>> and more or "a wide but not really widest type, so don't really trust it very
>> much".
> 
> It is the type used for preprocessor arithmetic, for example.

Yep.  Happens to always coincide with long long though (not in rank, but 
in width), so not much would be lost by using long long.

> 
> intmax_t was discussed at length in WG14, and while there was agreement on
> reducing its uses (hence the change to floating-point return types for
> fromfp functions, for example, see bug 28327), there was not agreement on
> any particular form of obsolescence.  And it *is* useful in practice for
> printing types such as off_t or mode_t with no corresponding printf
> formats; those could just do with appropriate constraints to be no wider
> than intmax_t when a future POSIX revision is based on C2x.

Yes, and yet the same can be said about long long.  intmax_t is one less 
character (both in the type name, and in "j"), but apart from that, no 
much benefit.

Do we really need a typedef for a type that is guaranteed to be as wide 
as any system data type (effectively that is long long)?  It wasn't the 
original intention for intmax_t, AFAIK, and neither is necessary.  I 
considered changing to long long in the man pages to keep it simple.

> 
>> If there's no hope in intmax_t, we should just mark the type as obsolescent,
>> and discard any idea of having a "widest" type at all.
> 
> I don't think it's useful to try to rehash here discussions that were had
> at length in WG14.

Okay.

> 
>> Ahh, you anticipated part 2 of my plan.  Deprecate "j", and add a new set of
>> macros PRIdMAX and the like.  This type has it deserved.  But I know those
>> macros aren't very well received, so it is just part 2.
> 
> The actual direction is to move away from those macros (adding length
> modifiers for printing intN_t / int_leastN_t / int_fastN_t without needing
> to use such macros any more).

While for fixed-width types it makes sense to use fixed strings "w<N>", 
for variable-width types, it doesn't so much.  Otherwise, the types are 
really fixed-width, as far as the ABI is concerned, even if they are not 
explicit-width.  I think having a macro PRIdMAX could make sense.  But 
of course it depends on the meaning of intmax_t.

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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-09-13 23:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-13 15:18 Alex Colomar
2022-09-13 15:28 ` Alejandro Colomar
2022-09-13 15:34 ` Alejandro Colomar
2022-09-13 18:27 ` Joseph Myers
2022-09-13 18:47   ` Paul Eggert
2022-09-13 19:30     ` Joseph Myers
2022-09-13 20:59       ` Paul Eggert
2022-09-13 22:43   ` Alejandro Colomar
2022-09-13 22:56     ` Joseph Myers
2022-09-13 23:43       ` Alejandro Colomar [this message]
2022-09-14 16:41         ` Joseph Myers
2022-09-14 19:03           ` JeanHeyd Meneide
2022-09-15 12:33             ` Alejandro (Alex) Colomar

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=43da981a-5727-d521-9aa2-a56aa9cd2f53@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=wg14@soasis.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 read-only IMAP folder(s) and NNTP newsgroup(s).