I just noticed an interesting gcc property regarding bit fields. If I create a struct as follows:
template <int N> struct C { unsigned long long data : N; };
Then on amd64:
- s -m64, for N ε <1, 64>,
sizeof(C) == 8 ; - s -m32, for N ε <1, 32>,
sizeof(C) == 4 and for N ε <33, 64>, sizeof(C) == 8 .
(with sizeof(unsigned long long) == 8 ).
It looks like this is similar to C99 / C ++ 11 uint_fastXX_t , except for the fact that on my system sizeof(uint_fast8_t) == 1 . But, for example, I cannot reproduce anything like that with __int128 (which always leads to sizeof(C) == 16 ).
Does it seem to you a good idea to use the above struct as a replacement for the "poor" for uint_fastXX_t in C ++ 98?
source share