public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* aligned_alloc man page and restrictions on alignment values
@ 2026-02-05 10:05 Jonathan Wakely
  2026-02-05 13:17 ` Alejandro Colomar
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Wakely @ 2026-02-05 10:05 UTC (permalink / raw)
  To: linux-man

Hi,

I don't understand what "except for the added restriction" means in
aligned_alloc(3) here:

      The  obsolete  function  memalign()  allocates  size bytes and returns a
      pointer to the allocated memory.  The memory address will be a  multiple
      of alignment, which must be a power of two.

      aligned_alloc() is the same as memalign(), except for the added restric‐
      tion that alignment must be a power of two.


Does it mean that aligned_alloc doesn't have the power of two
restriction? If so, describing that as an "added" restriction is very
confusing. What was it added to? It's not added to aligned_alloc if
it's absent from aligned_alloc.

Does it mean "aligned_alloc() is the same as memalign(), except that
alignment need not be a power of two"? That would match my
understanding of the C standard, which says that aligned_alloc() has
well-defined behaviour for invalid alignments, failing by returning a
null pointer.

But posix_memalign also has well-defined behaviour for invalid
alignments. POSIX requires that posix_memalign handles invalid
alignments by returning NULL and setting errno to EINVAL. Which is
what aligned_alloc does too. So what exactly is the restriction here?
Does memalign have UB for invalid alignments, or does it fail and set
EINVAL? How is that different from aligned_alloc and posix_memalign?

Wording the linux man page in terms of "must be" and wording POSIX in
terms of "shall be" makes it sound like you get UB if you fail to meet
it, but as far as I can tell you just get a null pointer. The APIs are
well-defined for invalid alignment arguments.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-02-06 14:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-05 10:05 aligned_alloc man page and restrictions on alignment values Jonathan Wakely
2026-02-05 13:17 ` Alejandro Colomar
2026-02-05 13:26   ` Alejandro Colomar
2026-02-05 13:55   ` Jonathan Wakely
2026-02-05 14:04     ` Alejandro Colomar
2026-02-05 15:23     ` Carlos O'Donell
2026-02-05 15:53       ` Alejandro Colomar
2026-02-06 14:09         ` Carlos O'Donell
2026-02-06 14:14           ` Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox