During a code review, this function was being reviewed:
static inline bool is_aligned(const void *ptr, size_t byte_count)
{
return (uintptr_t) ptr % byte_count == 0;
}
on which @Toby Speight said:
Any kind of object pointer can be converted to
uintptr_t
, but arithmetic on this integer is unspecified. This test might work on your platform, but there are systems (notably, ia32 segmented memory architectures) where it’s likely to be incorrect.
In that case, what is the correct way to do this (find the remainder)?