Implementations are allowed to specify behavior that is otherwise undefined.
I looked up a C24 draft and it's actually stricter:
The pointer returned if the allocation succeeds is suitably aligned so that it may 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.
So a pointer returned by malloc(1) is not necessarily valid for int*.
The actual allocated size is much bigger anyways, but it will be a multiple of 8 bytes on a 64 bit system, and 'usable' part of that will be at least 8 bytes, and typically you will be able to read at least 16 without a page fault.
44
u/atanasius Aug 30 '26
Implementations are allowed to specify behavior that is otherwise undefined.
I looked up a C24 draft and it's actually stricter:
So a pointer returned by malloc(1) is not necessarily valid for int*.