On 26 October 2016 at 21:33, Chris Glover
In this case, FWIW, on MSVC2015, the bit-twiddling version generates faster code than the mod version -- about 25% faster. I didn't test gcc or clang.
How often are you going to check this? I would do this only in debug.
On 27 October 2016 at 06:58, Michael Marcin
There's quite a large difference between "this object happens to land on a 16 byte alignment" and "what is the alignment of this object?" or even "is this object alignas(16)".
Yes, resorting to some bit-fiddling then: size_t whatIsTheAlignmentOfThisPointer ( const void* p_ ) { return ( size_t ) ( ( uintptr_t ) p_ & ( uintptr_t ) -( ( intptr_t ) p_ ) ); } Yes, it assumes twos-complement, and yes it will therefore possibly fail [running it] on your average IoT-water-cooker. degski