[Issue 2821] New: struct alignment inconsistent with C for { int, long }

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 8 22:07:58 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2821

           Summary: struct alignment inconsistent with C for { int, long }
           Product: D
           Version: 1.043
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: kamm-removethis at incasoftware.de


I couldn't find it in the spec right now, but as far as I remember D and C
structs are supposed to be aligned identically when the same types are used.

struct S {
  int i;
  long l;
}

In C (using gcc 4.1.2), the S.l.offsetof is 4 and the total size is 12. With
dmd the offsetof is 8 and the total size is 16.

Test code:
-- D code
import std.stdio;

struct S {
  int i;
  long l;
}

void main() {
  writefln("%d %d", S.sizeof, S.l.offsetof);
}
-- C code
#include <stdio.h>

struct S
{
  int i;
  long long l;
};

int main()
{
  struct S s;
  printf("%d %d\n", sizeof(s), (void*)&s.l - (void*)&s);
  return 1;
}
--


-- 



More information about the Digitalmars-d-bugs mailing list