4 ms·
>Can we have a #pragma that tells the compiler to abort with an error if the target machine uses any representation for signed integers other than twos-compleme
by Kristine1975 11y ago
>Can we have a #pragma that tells the compiler to abort with an error if the target machine uses any representation for signed integers other than twos-complement?
This should do it (off the cuff):
typedef int NOT_TWOS_COMPLEMENT[(unsigned int) -1 == UINT_MAX ? 1 : -1];
In C++ use static_assert.
- dsfuoi 11y agoI don't see how that would work. Casting -1 to an unsigned type is independent of representation and will always give the max unsigned value. C has _Static_assert.