In C, can you have a 128-bit bitfield [duplicate]

牧云@^-^@ 提交于 2019-12-25 09:18:05

问题


Is the following code legal?

struct BigInt {
     uint64_t a : 128;
};

回答1:


A bitfield must fit within a single int, so you're out of luck unless int is 128 bits on your platform.

(You were also missing a ; at the end of the struct prior to the edit.)




回答2:


Not legal in standard C11 (on most platforms; in principle, an int might be 128 bits, but I never met a platform having that). Read n1570 (draft specification).

But on some platforms recent compilers (e.g. GCC 6) provide __int128 as an extension. You won't use that as a bitfield, but as some kind of integral type.

See also this answer to a related question.



来源:https://stackoverflow.com/questions/41267458/in-c-can-you-have-a-128-bit-bitfield

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!