6.3.1.1p2 的含义,要点 2
Meaning of 6.3.1.1p2, bullet point 2
The following may be used in an expression wherever an int
or unsigned int
may be used:
An object or expression with an integer type (other than int
or unsigned int
) whose integer conversion rank is less than or equal to the rank of int
and unsigned int
.
A bit-field of type _Bool
, int
, signed int
, or unsigned int
.
第二个要点背后的意图是什么?
为什么要省略排名低于int
的其他类型的整型字段?
这是否意味着我可以做例如:
printf("%d\n", (struct{ _Bool x:1; }){0}.x);
但不是:
printf("%d\n", (struct{ unsigned short x:1; }){0}.x);
大概是因为6.7.2.1p5:
A bit-field shall have a type that is a qualified or unqualified version of _Bool
, signed int
, unsigned int
, or some other implementation-defined type. It is implementation-defined whether atomic types are permitted.
即无论如何,您不能可移植地创建其他类型的位域。
The following may be used in an expression wherever an
int
orunsigned int
may be used:
An object or expression with an integer type (other than
int
orunsigned int
) whose integer conversion rank is less than or equal to the rank ofint
andunsigned int
.A bit-field of type
_Bool
,int
,signed int
, orunsigned int
.
第二个要点背后的意图是什么?
为什么要省略排名低于int
的其他类型的整型字段?
这是否意味着我可以做例如:
printf("%d\n", (struct{ _Bool x:1; }){0}.x);
但不是:
printf("%d\n", (struct{ unsigned short x:1; }){0}.x);
大概是因为6.7.2.1p5:
A bit-field shall have a type that is a qualified or unqualified version of
_Bool
,signed int
,unsigned int
, or some other implementation-defined type. It is implementation-defined whether atomic types are permitted.
即无论如何,您不能可移植地创建其他类型的位域。