What is the type of a bitfield?

2020-02-21 07:18发布

I can't find anywhere in the C standard where this is specified. For example, in

struct { signed int x:1; } foo;

is foo.x an lvalue of type int, or something else? It seems unnatural for it to be an lvalue of type int since you cannot store any value of type int in it, only 0 or -1, but I can't find any language that would assign it a different type. Of course, used in most expressions, it would get promoted to int anyway, but the actual type makes a difference in C11 with _Generic, and I can't find any language in the standard about how bitfields interact with _Generic either.

7条回答
2楼-- · 2020-02-21 08:08

I would suspect that this would depend on:

  1. The compiler
  2. Optimization settings
  3. The maximum number of bits in the bit field
查看更多
登录 后发表回答