Are padding bits always zero?
Honey via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 24 07:32:19 PDT 2017
On Saturday, 24 June 2017 at 12:41:47 UTC, Steven Schveighoffer
wrote:
> Any padding bits between fields should be 0 as long as the
> struct is initialized (i.e. as long as you don't do Struct s =
> void).
>
> Padding bits after the fields I assume would be 0, but I don't
> know if this is defined. It's possible the compiler doesn't
> consider those bits to be part of the struct, and just there
> for alignment.
>
> There is no spec for this, but I know that when the compiler
> has to fill gaps with something it chooses 0.
Thanks. Your answer has generated more questions. ;-)
Let's say, I have a struct S of size n with m bits of padding at
the end. How can I find m?
Is it possible to provide a facility Pad such that for any struct
T, Pad!T is a struct that mimics T but contains explicit instead
of implicit padding? E.g.
struct Foo
{
ubyte b;
double d;
int i;
}
struct Pad!Foo
{
ubyte b;
ubyte[7] __padding_0;
double d;
int i;
ubyte[4] __padding_1;
}
More information about the Digitalmars-d-learn
mailing list