Subject: Re: [PATCH] Properly align memory allocations and temporary buffers

From: "brian m. carlson" <[email-masked]>
Date: Fri, 7 Jan 2022 00:31:45 +0000

On 2022-01-07 at 00:10:21, Junio C Hamano wrote:
> Jessica Clarke <[email-masked]> writes:
> 
> > This is also true of uint128_t, it doesn’t fit in a uintmax_t either.

I don't have this type from either GCC or Clang on my Debian amd64/sid
system.  I know those compilers support 128-bit values because Rust uses
them, but they are not exposed in standard C and therefore those
compilers appear to be compliant when run in standards mode.

> uintmax_t is supposed to be an unsigned integer type capable of
> representing any value of any unsigned integer type, so if you have
> 128-bit unsigned integer, your uintmax_t should be at last that
> wide, or your uintmax_t is not uintmax_t as far as C standard is
> concerned, no?
> 
> uintptr_t is an unsigned integer type that any valid pointer to void
> can be converted to this type, then converted back to pointer to
> void, and the result will compare equal to the original pointer.  So
> the value of uintptr_t cannot be represented by uintmax_t, there is
> something wrong.

Yes, this is the case.  The C standard mandates this behavior.

Now, as far as I'm aware, the standard does not mandate that that
uintmax_t have the strictest alignment requirements of any integral
type.  It could be that other types have stricter requirements, for
example, on some systems.  But it is required that conversion from void *
to uintptr_t to uintmax_t to uintptr_t to void * preserve the
functionality of the pointer.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA