2026-10-14
Chris Kennelly, Justin King, Charles Munger (rationale, history)
Charles Munger, Jens Gustedt, Joseph Myers (wording)
| number | Title | Authors | Remarks |
|---|---|---|---|
| n3991 | this paper | Wording Group | |
| n3899 | Memory allocation with size feedback v4 | Chris Kennell et al. | rationale |
| N3953 | Draft minutes 2026 (summer) | David Svoboda | polled N3899, 2026-08-19 |
| N3886 | Working Draft | base for diff, 2026-06-26 |
none yet
liaisons to inform: WG21, Austin Group
| meeting | date | for | against | abstain |
|---|---|---|---|---|
| Ottawa | 2026-08 | 15 | 4 | 7 |
In general, we chose to simplify additions to the standard. In particular, we refer to behavior of existing functions where this is possible and only mark the differences where they occur.
We propose to avoid stepping on our user’s toes and only to add new
identifiers with a prefix. For functions and the proposed type we opted
for a stdc_ prefix as we now have
adopted it more widely in several places. For the struct members of
stdc_alloc_result_t we opted for the
prefix al_, in the line of such
structure members in other parts of the standard, similar to the members
of struct tm
for example.
struct membersOne option question was if the list of described members of stdc_alloc_result_t should be exact or if
implementations should be allowed to add other implementation-defined
members. In the text, the difference between the two would just be the
word exactly or its
omission in one place. We leave this as a decision between alternatives
to WG14.
We also observed that each of the paragraphs 2 of free_sized (7.25.4.7) and free_aligned_sized (7.25.4.8) had wording
problems.
They used “may” to express a user requirement. We propose to change this to “shall”.
Also both functions unconditionally stated that the result of certain allocation functions should not be used. If the allocation function returned a null pointer, evidently such a pointer can still be passed to a deallocation function. We propose to add the condition that the allocation call was successful.
Deletions in the shown standard text are as shown here,
additions as shown here, code snippets as here. These may be rendered differently
according to the style in which the document is shown by your browser
but should always be well distinguishable. In the style provided there
are two visual distinctions:
Close to each other proposed changes resemble like this.
Text presented with an orange background such as here, presents a possible omission in new wording (proposed to WG14 as alternative).
At a suitable position, add to the list of types in 7.25 General utilities <stdlib.h>, 7.25.1 General p3
which is a structure type that is the type of the value returned by thestdc_alloc_result_tstdc_alloc_at_leastandstdc_aligned_alloc_at_leastfunctions,…
In 7.25.4.1 General
Modify p1
1 The order and contiguity of storage allocated by successive calls to the
aligned_alloc,stdc_alloc_at_least,stdc_aligned_alloc_at_least,calloc,malloc, andreallocfunctions is unspecified. The pointer returned if the allocation succeeds is suitably aligned so that it can be assigned to a pointer to any type of object with a fundamental alignment requirement and size less than or equal to the size requested, or in the case ofstdc_aligned_alloc_at_leastandstdc_alloc_at_least, the size returned. It can then be used to access such an object or an array of such objects in the space allocated (until the space is explicitly deallocated). The lifetime of an allocated object extends from the allocation until the deallocation. Each such allocation shall yield a pointer to an object disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer is returned. If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned to indicate an error, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object.
Add a new paragraph (position at the discretion of the editor)
1′ The
stdc_alloc_result_tstructure shall contain exactly the following members, in either order:If thevoid* al_ptr; size_t al_size;stdc_alloc_at_leastandstdc_aligned_alloc_at_leastfunctions successfully allocate an object, they return a structure whereal_ptris the address of the allocated object and the value ofal_sizeis not0and is the size of the allocated object; otherwiseal_ptris a null pointer andal_sizeis0.
Add a new subclause
7.25.4.x The
stdc_alloc_at_leastfunction
Synopsis
#include <stdlib.h> stdc_alloc_result_t stdc_alloc_at_least(size_t min_size);Description
The
stdc_alloc_at_leastfunction provides the same functionality as themallocfunction, but where the allocated object has a possible size that is equal or greater than the requested sizemin_size.Returns
The
stdc_alloc_at_leastfunction returns a structure of typestdc_alloc_result_tcomprising both a pointer to the newly allocated object and the resulting size of that object. Ifmin_sizewas0or the allocation failed, theal_sizemember is0and theal_ptrmember is a null pointer. Otherwise the value of theal_sizemember is greater than or equal tomin_size.Recommended practice
It is recommended that the implementation allocates an object with a size larger than
min_sizeif otherwise it is not able to use trailing bytes aftermin_sizebytes until the allocated object is deallocated.
Add a new subclause
7.25.4.y The
stdc_aligned_alloc_at_leastfunctionSynopsis
#include <stdlib.h> stdc_alloc_result_t stdc_aligned_alloc_at_least(size_t alignment, size_t min_size);Description
The
stdc_aligned_alloc_at_leastfunction provides the same functionality as thealigned_allocfunction, but where the allocated object has a possible size that is equal or greater than the requested sizemin_size. If the value ofalignmentis not a valid alignment supported by the implementation the function shall fail.Returns
The
stdc_aligned_alloc_at_leastfunction returns a structure of typestdc_alloc_result_tcomprising both a pointer to the newly allocated object and the resulting size of that object. Ifmin_sizewas0or the allocation failed, theal_sizemember is0and theal_ptrmember is a null pointer. Otherwise the value of theal_sizemember is greater than or equal tomin_sizeand the value of theal_ptrmember is aligned to at least the requested alignment.Recommended practice
It is recommended that the implementation allocates an object with a size larger than
min_sizeif otherwise it is not able to use trailing bytes aftermin_sizebytes until the allocated object is deallocated.
Modify the description in
7.25.4.7 The
free_sizedfunction…
Description
2 If
ptris a null pointer or if it is the result obtained from a call tomalloc,realloc, orcalloc, where sizesizeis equal to the requested allocation size, this function is equivalent tofree(ptr). Ifptrand m are the resulting pointer and object size obtained from a call tostdc_alloc_at_least(n), andsizeis in the closed interval [n, m] this function is equivalent to free(ptr). Otherwise, the behavior is undefined.The result of anThe result of a successful call toaligned_alloccall may not be passed tofree_sized.aligned_allocorstdc_aligned_alloc_at_leastshall not be passed tofree_sized.
Modify the description in
7.25.4.8 The
free_aligned_sizedfunction…
Description
2 If
ptris a null pointer or if it is the result obtained from a call toaligned_alloc, wherealignmentis equal to the requested allocation alignment andsizeis equal to the requested allocation size, this function is equivalent tofree(ptr). Ifptrand m are the resulting pointer and object size obtained from a call tostdc_aligned_alloc_at_least(alignment,n), andsizeis in the closed interval [n, m] this function is equivalent to free(ptr). Otherwise, the behavior is undefined.The result of anThe result of a successful call tomalloc,calloc, orrealloccall may not be passed tofree_aligned_sized.malloc,calloc,realloc, orstdc_alloc_at_leastshall not be passed tofree_aligned_sized.