คำถามติดแท็ก signed-integer

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 ++ ผลลัพธ์ของโค้ดที่เป็นที่ไม่คาดคิด , ถูกปิดใช้งาน !! แม้ว่าจะมีการให้คำอธิบายที่เกี่ยวข้องกับ "บิตเครื่องหมาย" …

โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.