Summary: Indicate default alignment with 0.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from Dan G. <> 2012-01-29 09:13:18 PST ---
Created an attachment (id=1071)
align.patch - Patch file

The patch modifies DMD to use the value 0 when default alignment should be
used.  It allows implementations to easily deviate from how DMD handles field
alignment and keep the requirement that `align` will restore default alignment.

Below is an attempt to describe why this is useful.


DMD and GDC different in how they interpret the align keyword.  GDC will align
all fields to the specified size.  DMD appears to still take into consideration
the required alignment for a given type.

The issue arises when one wishes to return to default alignment.

"align by itself sets it to the default, which matches the default member
alignment of the companion C compiler."

GDC uses the value passed to AlignDeclaration to force the alignment of field
members.  The front end currently treats default alignment as system alignment
generally 8.  This will indicate to GDC all field members should be aligned on
8 bytes instead of restoring default alignment.

The following test shows the unlikely situation when this becomes an issue. 
This situation in unlikely until conditional complication comes into play since
a trivial workaround is to use braces.

// For GDC.
struct A 
    byte a; // 2 bytes
    byte b; // 2 bytes
    byte c; // 2 bytes
  align: // restore default alignment. Translates to align(8)
    byte d; // 8 bytes.  1 is expected
    byte e; // 8 bytes.  1 is expected
    byte f; // 8 bytes.  1 is expected

align struct A {} is remade into align(8) struct A {}.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to