www.digitalmars.com         C & C++   DMDScript  

c++.dos.32-bits - alignment

reply "ZaitcevE.V." <Genior km.ru> writes:
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.
Oct 23 2001
next sibling parent Roland <rv ronetech.com> writes:
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.
Oct 23 2001
prev sibling parent Heinz Saathoff <hsaat bre.ipnet.de> writes:
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
Oct 23 2001