[PATCH] inttypes.h: imaxabs(3): Implement as a macro

JeanHeyd Meneide wg14@soasis.org
Wed Sep 14 19:03:19 GMT 2022


Dear Alejandro, Joseph,

On Wed, Sep 14, 2022 at 12:41 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Wed, 14 Sep 2022, Alejandro Colomar via Libc-alpha wrote:
>
> > > 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.
>
> It provides a clearer statement of intent to readers of the code than long
> long does.
>
> As I noted in the WG14 discussions of a few proposed obsoletions, just
> because some language feature is not useful for *all* the things some
> people might like to be able to use it for isn't a reason for obsoletion
> when it's still useful for *some* of those things.


     I agree here. I have a proposal to fix this, based on the
assembly labels and similar existing practice found on a lot of
compilers, and based on what BSDs such as NetBSD have been using for
25+ years to provide ABI stability despite shifting architectures and
types: https://thephd.dev/_vendor/future_cxx/papers/C%20-%20Transparent%20Aliases.html

     I would rather we not fall back to macros for all the reasons
Joseph and others mentioned (the standard library #undef macro reason
is also listed in the above-linked paper). I personally view the
exemptions we made for the upcoming C2x (C23) standard as stop-gaps to
allow important evolution and implementation work from, but not
general-purpose solutions. I think transparent aliases is a generic
solution to the problem and would achieve much of what we need to do,
but it will not be in until C2y/C3a (the next revision of the C
standard) if I work hard at it and polish the wording while surfacing
implementations. I also found a few embedded folks who similarly
suffered drawbacks because their platform's compiler could not deal
with the asm("") labels for ABIs, and broke the entire build on their
machine. So even for non-large systems, there's a real need for a
language-level indirection mechanism that has all the same properties
as normal functions.

     I hope that we can still make do with implementation extensions
while I (and others?) work to make proper strides in implementation.
And I apologize it took me this long to come up with these things; I
certainly do wish I was "faster on the draw" to solving these
problems, so to speak.

Best Wishes,
JeanHeyd


More information about the Libc-alpha mailing list