Thread overview |
---|
April 28, 2008 struct members align | ||||
---|---|---|---|---|
| ||||
I have some problem with struct alignment. My struct is: struct some_struct { ubyte member1; ubyte member2; ubyte member3; ushort member5; ushort member6; } The appearance of members is fixed. member5 shifted by 1 byte down to member6. How to fix this problem? |
April 28, 2008 Re: struct members align | ||||
---|---|---|---|---|
| ||||
Posted in reply to alxdef | alxdef wrote:
> I have some problem with struct alignment. My struct is:
> struct some_struct
> {
> ubyte member1;
> ubyte member2;
> ubyte member3;
> ushort member5;
> ushort member6;
> }
> The appearance of members is fixed. member5 shifted by 1 byte down to
> member6. How to fix this problem?
align(1) struct some_struct { ... } will do the trick, I think.
|
April 28, 2008 Re: struct members align | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lutger | Lutger Wrote:
> align(1) struct some_struct { ... } will do the trick, I think.
As Russians say: The fakir was drunk, trick is not has gone right. :-(
|
April 28, 2008 Re: struct members align | ||||
---|---|---|---|---|
| ||||
Posted in reply to alxdef | alxdef wrote:
> Lutger Wrote:
>
>> align(1) struct some_struct { ... } will do the trick, I think.
>
> As Russians say: The fakir was drunk, trick is not has gone right. :-(
Which compiler? Or have I misunderstood the question mayhaps, this program works under dmd 1.027:
struct some_struct
{
ubyte member1;
ubyte member2;
ubyte member3;
ushort member4;
ushort member5;
}
align(1) struct some_struct2
{
ubyte member1;
ubyte member2;
ubyte member3;
ushort member4;
ushort member5;
}
void main()
{
assert(some_struct.sizeof == 8);
assert(some_struct2.sizeof == 7);
}
|
Copyright © 1999-2021 by the D Language Foundation