gpt4 book ai didi

c - 6.3.1.1p2 的含义,要点 2

转载 作者:太空宇宙 更新时间:2023-11-04 02:24:13 29 4
gpt4 key购买 nike

6.3.1.1p2

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.

即无论如何,您不能可移植地创建其他类型的位域。

关于c - 6.3.1.1p2 的含义,要点 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53481722/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com