От: | Tilir | http://tilir.livejournal.com | |
Дата: | 09.10.14 12:55 | ||
Оценка: | 46 (2) |
#include <stdio.h>
struct bitflds
{
unsigned long long xxx: 21;
unsigned long long addr: 27;
unsigned long long yyy: 16;
};
int
main (void)
{
struct bitflds mess;
mess.addr = 0x54aull;
fprintf (stderr, "bad: 0x%llx\n", (unsigned long long ) (mess.addr << 21ull));
fprintf (stderr, "good: 0x%llx\n", ((unsigned long long ) mess.addr) << 21ull);
return 0;
}
bad: 0xffffffffa9400000
good: 0xa9400000
If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int