[Issue 16270] New: scoped Alignment
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jul 12 08:24:46 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16270
Issue ID: 16270
Summary: scoped Alignment
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: TeddyBear12311 at gmail.com
C++ has the ability to align all members of struct/class in a scope: e.g.,
#pragma pack(push,16)
Without this in D, it requires aligning each type manually. It may seem like
trivial work, but it is not and posses serious problems when converting C code
that uses scoped alignment.
A simple
align(n)
{
struct x { int a, b, c; }
}
would be identical do
align(n) struct x
{
align(n)
int a, b, c;
}
It should be a trivial enhancement. I'm only concerned about the member
alignment.
Alternatives are
align(n)
{
struct x { int a, b, c; }
}
would be identical do
struct x
{
align(n)
int a, b, c;
}
or
malign(n)
{
struct x { int a, b, c; }
}
would be identical do
struct x
{
align(n)
int a, b, c;
}
pragma could be used
pragma(align(n))
struct x { int a, b, c; }
struct y { int a, b, c; }
pragma(align(m))
struct z { int a, b, c; }
would be identical do
struct x
{
align(n)
int a, b, c;
}
struct y
{
align(n)
int a, b, c;
}
struct z
{
align(m)
int a, b, c;
}
The responses that a simply search and replace are not acceptable. It is not
robust, may quietly fail, etc. Adding by hand to every struct or member is also
not acceptable because because it depends on size. (trivial for one struct but
not so for 100 structs)
I believe this is not an enhancement but an oversight. It is required for
large complex code unless man hours is not a factor.
--
More information about the Digitalmars-d-bugs
mailing list