Hi,
In the alligned memory allocation post (a quite good article indeed).
Christian Bau suggests the following:
My question is: Is the following statement portable (I have turned unsigned long into uintptr_t) - My concern is more about the % or & operators ?
Guilleuss
In the alligned memory allocation post (a quite good article indeed).
Christian Bau suggests the following:
Code:
char* p = calloc (bytes + alignment + sizeof (void *)); char* q = p + sizeof (void *) + alignment; q -= ((unsigned long) q) % alignment; // If you want your code unreadable like the original author, // then change the last line to // q -= ((unsigned long) q) & (alignment - 1);
My question is: Is the following statement portable (I have turned unsigned long into uintptr_t) - My concern is more about the % or & operators ?
Code:
q -= ((uintptr_t) q) % alignment;
Comment