I'm using posix_memalign (had trouble with align_alloc) to allocate (inside my own new) so I have a void*. I need it as int for instance to compute alignment:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main() {
void *ptr;
auto align{4096}, size{10000};
posix_memalign( &ptr,align,size );
cout << ptr << endl; // works
cout << ptr % align << endl; // not
return 0;
}
I thought in modern C++ static_cast<long> would be the right way , but that gives an error that that's not allowed on a void*. So what is the proper way? I can of course use old-style C casts, but I'm trying to avoid those.