c++.dos.32-bits - alignment
- ZaitcevE.V. (8/8) Oct 23 2001 Mr Walter. How it is possible to bypass a problem of alignment?
- Roland (20/28) Oct 23 2001 Me i use this (I'm not sure it is up to date but it works):
- Heinz Saathoff (15/25) Oct 23 2001 You can specify alignment with the pragma pack. In your case you can use...
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
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
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









Roland <rv ronetech.com> 