Aligned_alloc function requirements

I am considering the aligned-alloc () explanation: http://en.cppreference.com/w/c/memory/aligned_alloc

void *aligned_alloc( size_t alignment, size_t size );

"Allocation of size bytes of the uninitialized storage whose alignment is set by alignment. The size parameter must be an integer multiple of alignment."

However, the sample code uses it like this:

int *p2 = aligned_alloc(1024, 10*sizeof *p2);

10 * sizeof * p is 40, so it is not an integer multiple of 1024.

What don’t I understand?

+4
source share
2 answers

, , C11 : undefined, DR 460 , , : http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2072.htm

, , .

+4

:

size, alignment alignment, , (C11, , undefined , DR 460).

, C11, DR 460, , "undefined" "" . , ", ". undefined.

, ( , , 1024 * sizeof *p2).

+1

Source: https://habr.com/ru/post/1663191/


All Articles