I know C++11 provides alignof, alignas and align, but in this case I want to check an input buffer that is already allocated.
I know also that C provides uintptr_t
to precisely fit a pointer type in a conversion to integer (and then checking alignment would be easy), but this data type is not guaranteed to be there in C++/C++11.
The question is answered here for C. It seems that a conversion to any integer would be ok in this case, but in C++ I get a "loses precision" warning.
So, now I look at Converting a pointer into an integer, but there I find an abundant use of uintptr_t
, which is not guaranteed to be there.
So, what is the best way to check if an input pointer is aligned in C++/C++11?
(Note: After all this research and reasoning I came up with a solution, but I am looking forward to other proposals!)