Implement C23 memalignment

Joseph Myers josmyers@redhat.com
Thu Oct 2 11:32:37 GMT 2025


On Wed, 1 Oct 2025, Collin Funk wrote:

> Joseph Myers <josmyers@redhat.com> writes:
> 
> > +/* Return the alignment of P.  */
> > +size_t
> > +memalignment (const void *p)
> > +{
> > +  size_t i = (size_t) p;
> > +  return i & -i;
> > +}
> 
> Doesn't it make more sense to cast the pointer to uintptr_t? In practice
> it should be the same as size_t, but theoretically the cast could change
> the value and be conformant to ISO C, unlike with uintptr_t.

The result has to be returned in size_t, and glibc definitely doesn't 
support platforms where they are of different width.

-- 
Joseph S. Myers
josmyers@redhat.com



More information about the Libc-alpha mailing list