| Program termination | |||||||||||||||||||||
| |||||||||||||||||||||
| Unreachable control flow | |||||||||||||||||||||
(C23) | |||||||||||||||||||||
| Communicating with the environment | |||||||||||||||||||||
| |||||||||||||||||||||
| Memory alignment query | |||||||||||||||||||||
memalignment (C23) | |||||||||||||||||||||
| Signals | |||||||||||||||||||||
| Signal types | |||||||||||||||||||||
| Non-local jumps | |||||||||||||||||||||
| Types | |||||||||||||||||||||
Defined in header <stdlib.h> | ||
size_t memalignment(constvoid*p); | (since C23) | |
Returns the maximum alignment satisfied by the provided address. The return value can be greater than any alignment value supported by the implementation. Ifp is a null pointer value,0 is returned to indicate that the pointer cannot be used to access an object of any type.
If the return value compares is greater than or equal toalignof(T), the alignment requirement for the typeT is satisfied by the pointer.
Afreestanding implementation needs to providememalignment.
Contents |
| p | - | pointer to query alignment |
The alignment value ofp, or0 ifp is a null pointer value.
On common platforms where
this function can be implemented asreturn(size_t)p&-(size_t)p;.
#include <stdio.h>#include <stdlib.h> int main(){ alignas(128)int i=0;printf("%zu\n%zu\n", memalignment(nullptr), memalignment(&i));}
Possible output:
0128
(C11) | allocates aligned memory (function)[edit] |
(C23) | deallocates previously allocated sized and aligned memory (function)[edit] |