I'm implementing a library, that uses many bit tricks under the hood. One of the requirements is for the signed integer right shift to be arithmetic.
Whether the "right-bit-shift on negative signed integer" fills the empty left side with zeroes or ones is implementation-defined - but how can I check which one it is during compilation?
One of my ideas was:
static_assert( ((int32_t{-1}) >> 31) == -1, "");
static_assert( ((int64_t{-1}) >> 63) == -1, "");
But can I be sure, that this operation will be performed the same way both during compile time and runtime? Is there any better way to check that?