Questions tagged «implementation-defined-behavior»




6
为什么将值分配给位字段却没有返回相同的值?
我在Quora帖子中看到了以下代码: #include <stdio.h> struct mystruct { int enabled:1; }; int main() { struct mystruct s; s.enabled = 1; if(s.enabled == 1) printf("Is enabled\n"); // --> we think this to be printed else printf("Is disabled !!\n"); } 在C和C ++中,代码的输出都是意外的, 被禁用 !! 尽管在那篇文章中给出了与“符号位”相关的解释,但我无法理解,我们可能会设置一些东西,然后又不能按原样反映。 有人可以给出更详细的解释吗? 注意:两个标签C 和 C ++因为它们的描述位域的标准略有不同,所以是必需的。请参阅有关C规范和C ++规范的答案。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.