Implement C23 memalignment

Joseph Myers josmyers@redhat.com
Thu Oct 2 11:34:05 GMT 2025


On Thu, 2 Oct 2025, Florian Weimer wrote:

> * Joseph Myers:
> 
> > diff --git a/manual/memory.texi b/manual/memory.texi
> > index 6a70168e61..1e30631125 100644
> > --- a/manual/memory.texi
> > +++ b/manual/memory.texi
> > @@ -1135,6 +1135,17 @@ The @code{valloc} function is obsolete and @code{aligned_alloc} or
> >  @code{posix_memalign} should be used instead.
> >  @end deftypefun
> >  
> > +You can determine the alignment of a pointer with the
> > +@code{memalignment} function.
> > +
> > +@deftypefun size_t memalignment (void *@var{p})
> > +@standards{C23, stdlib.h}
> > +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
> > +
> > +This function, defined in C23, returns the alignment of @var{p}, as a
> > +power of two.  If @var{p} is a null pointer, it returns zero.
> > +@end deftypefun
> 
> Does the pointer have to be a valid object pointer?  I think we should
> support arbitrary bit patterns as a GNU extension.

C23 suggests it has to be a valid pointer to an object (or a null 
pointer).  This implementation supports arbitrary bit patterns.

-- 
Joseph S. Myers
josmyers@redhat.com



More information about the Libc-alpha mailing list