Thread overview | |||||
---|---|---|---|---|---|
|
October 23, 2001 alignment | ||||
---|---|---|---|---|
| ||||
Mr Walter. How it is possible to bypass a problem of alignment? struct xxx { short a; char *pa; }; sizeof (struct xxx) gives 8, instead of expected 6. It is important for compatibility. |
October 23, 2001 Re: alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to ZaitcevE.V. | Me i use this (I'm not sure it is up to date but it works): //set alignment one byte #ifdef __SC__ #pragma SC align 1 #else #pragma option -a- #endif struct MyStruc { . . }; //restore previous alignment #ifdef __SC__ #pragma SC align #else #pragma option -a. #endif Ciao Roland "ZaitcevE.V." a écrit : > Mr Walter. How it is possible to bypass a problem of alignment? > > struct xxx > { > short a; > char *pa; > }; > > sizeof (struct xxx) gives 8, instead of expected 6. It is important for > compatibility. |
October 23, 2001 Re: alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to ZaitcevE.V. | ZaitcevE.V. schrieb... > How it is possible to bypass a problem of alignment? > > struct xxx > { > short a; > char *pa; > }; > > sizeof (struct xxx) gives 8, instead of expected 6. It is important for > compatibility. You can specify alignment with the pragma pack. In your case you can use it this way: #pragma pack(push, 2) //alignment is now 2 struct xxx { short a; char *pa; }; #pragma pack(pop) // alignment restored to the old state push/pop is not necessary but I find them very usefull as you don't have to reset the alignment to a fixed value. Regards, Heinz |
Copyright © 1999-2021 by the D Language Foundation