[Issue 23427] New: ImportC: some bitfield combinations lead to wrong size struct
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Thu Oct 20 02:13:24 UTC 2022
    
    
  
https://issues.dlang.org/show_bug.cgi?id=23427
          Issue ID: 23427
           Summary: ImportC: some bitfield combinations lead to wrong size
                    struct
           Product: D
           Version: D2
          Hardware: All
                OS: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dave287091 at gmail.com
On macOS, the following C code compiles without failing a static assertion
using apple clang. Dmd triggers the static assertion. I haven’t tested other
platforms.
_Static_assert(sizeof(unsigned) == 4, "");
struct A {
    unsigned x :8;
    unsigned y :4;
    unsigned z :20;
};
_Static_assert(sizeof(struct A)==4, "");
struct B {
    unsigned x :4;
    unsigned y :2;
    unsigned z :26;
};
_Static_assert(sizeof(struct B)==4, "");
struct C {
    unsigned x :4;
    unsigned y :4;
    unsigned z :24;
};
_Static_assert(sizeof(struct C)==4, ""); // This one fails
--
    
    
More information about the Digitalmars-d-bugs
mailing list