www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7362] New: forward referenced inner struct with align(1) doesn't add to offset of next field when used inside a union of another struct, that is nested in the same outer struct

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

           Summary: forward referenced inner struct with align(1) doesn't
                    add to offset of next field when used inside a union
                    of another struct, that is nested in the same outer
                    struct
           Product: D
           Version: D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: Marco.Leise gmx.de



This happened to me when I designed data structures for CD sectors, and used an
outer struct to wrap all the different sector layouts (Mode1/2 CDs, ...). The
short code below is more suited for a unittest:

    struct Outer {
        struct Inner1 {
            union { 
                Inner2 a;
            } 
            byte I_AM_AT_THE_WRONG_OFFSET;
        }

        align(1) struct Inner2 {
            ubyte x;
        }
    }

    void main() {
        writeln(Outer.Inner1.I_AM_AT_THE_WRONG_OFFSET.offsetof);
    }

This prints '0', which means that field 'I_AM_AT_THE_WRONG_OFFSET' wasn't
correctly offset behind field 'a'. It works correctly when
a) align(1) is removed
b) Inner2 is declared before Inner1
c) 'a' is not inside a union block

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


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com



PDT ---
Returns 1 on Win32 2.059

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


Marco Leise <Marco.Leise gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |2.059



Yes, it has been fixed in the mean time. Add this to the solved bugs for 2.059!

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