Google. , __attribute__((packed)).
http://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Type-Attributes.html
24 typedef struct __uint48_t uint48_t;
25 struct __attribute__((packed)) __uint48_t {
26 uint64_t _m:48;
27 };
29 void test()
30 {
31 uint48_t a;
32 a._m = 281474976710655;
33 printf("%llu", a._m);
34 printf("%u", sizeof(a));
35
36 a._m = 281474976710656;
37 printf("%llu", a._m);
38 }
main1.c: In function ‘test:
main1.c:36:2: warning: large integer implicitly truncated to unsigned type [-Woverflow]
$ ./a.out
281474976710655
6
0
, , Windows, .
, , .
By the way, I still don’t know what is the best way to resolve this issue. Using struct makes things a little awkward (do you need to call a._minstead a, could we handle this?) But at least it seems safer than just using uint64_t.
source
share