www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8383] New: 64-bit ABI: unions not the same size as in C in some situations

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8383

           Summary: 64-bit ABI: unions not the same size as in C in some
                    situations
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: code klickverbot.at



---
Originally reported by "bll" at http://www.dsource.org/projects/ldc/ticket/475:

---
#include <stdio.h>
#include <stdlib.h>

union a {
  long double a1;
  char        ac[20];
};

int
main (int argc, char *argv[]) {
  union a a;
  printf ("C\n");
  printf ("sizeof a: %d\n", sizeof (a));
  printf ("sizeof a.a1: %d\n", sizeof (a.a1));
  printf ("sizeof a.ac: %d\n", sizeof (a.ac));
  printf ("offsetof a.ac: %d\n", (int) ((char *) &a.ac - (char *) &a.a1));
  return 0;
}
---
yields
---
C
sizeof a: 32
sizeof a.a1: 16
sizeof a.ac: 20
offsetof a.ac: 0
---

but

---
import std.stdio;

union ua {
  real     a1;
  char     ac[20];
};

int
main (string argv[]) {
  ua a;
  writefln ("D");
  writefln ("sizeof a: %d", a.sizeof);
  writefln ("sizeof a.a1: %d", a.a1.sizeof);
  writefln ("sizeof a.ac: %d", a.ac.sizeof);
  writefln ("offsetof a.ac: %d", a.ac.offsetof);
  return 0;
}
---
yields
---
D
sizeof a: 24
sizeof a.a1: 16
sizeof a.ac: 20
offsetof a.ac: 0
---

when compiling on Linux x86_64.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 13 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8383


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME



With github head for D2, this gives sizeof a: 32
when compiled with -m64 on Linuxx86_64.
It only gives sizeof: a == 20 when compiled with -m32.
This is true even on 1.073, released five months before this bug report was
made.
So I cannot reproduce this at all. Did the original poster fail to use the -m64
flag?

It could of course have been an even older bug which was fixed before the start
of 2012.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 27 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8383




PST ---
Hm, strange, I was sure I could repro this using both DMD and LDC at some point
(and yes, building with -m64). In any case, thanks for taking the time to look
at this.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 27 2012