www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Struct with no alignment ?

reply tsalm <tsalm free.fr> writes:
Hello,

Is there a way to use a sort of struct which is not submit to alignment ?

For example :

struct MyStruct { long a; int b; }

have a size of 16 bytes.
But I only need 12.

Is there a way to have a sort of struct without alignment's system ?


Thanks in advance,
TSalm.
Oct 11 2008
next sibling parent Frank Benoit <keinfarbton googlemail.com> writes:
align(1) struct{ ... }
Oct 11 2008
prev sibling parent reply torhu <no spam.invalid> writes:
tsalm wrote:
 Hello,
 
 Is there a way to use a sort of struct which is not submit to alignment ?
 
 For example :
 
 struct MyStruct { long a; int b; }
 
 have a size of 16 bytes.
 But I only need 12.
 
 Is there a way to have a sort of struct without alignment's system ?
 
 
 Thanks in advance,
 TSalm.
align(1) struct MyStruct { long a; int b; } http://www.digitalmars.com/d/1.0/attribute.html#align
Oct 11 2008
parent tsalm <tsalm free.fr> writes:
 Hello,
  Is there a way to use a sort of struct which is not submit to  
 alignment ?
  For example :
  struct MyStruct { long a; int b; }
  have a size of 16 bytes.
 But I only need 12.
  Is there a way to have a sort of struct without alignment's system ?
   Thanks in advance,
 TSalm.
align(1) struct MyStruct { long a; int b; } http://www.digitalmars.com/d/1.0/attribute.html#align
Awesome! D is really an excellent language Thanks you Torhu and Frank Benoit.
Oct 11 2008