This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Data alignment with gcc
- To: gcc-help at gcc dot gnu dot org
- Subject: Data alignment with gcc
- From: Tim Jackson <tim at timj dot co dot uk>
- Date: Thu, 29 Mar 2001 09:32:30 +0100
Hi,
I am doing some work which involves using a defined class as follows:
class MESSAGE
{
public:
unsigned char Type;
unsigned char Length;
unsigned long Sequence;
char Data[251];
};
For reasons that I won't go into to keep this mail brief, it is essential
that the class data members are in the order given above and most
importantly *NOT* aligned to word boundaries. (essentially, an object is
to be dumped to a TCP socket and must conform to a given protocol).
I'm using gcc/g++ 2.95.2 on an i586 Linux machine (will gladly upgrade to
.3
if necessary).
With MS Visual Studio (!) one can do something along these lines to "pack"
a structure so that data members are not aligned:
#pragma pack(push, MESSAGES_STRUCT, 1)
(...)
#pragma pack(pop, MESSAGES_STRUCT)
Could anyone explain how to achieve a similar result with gcc/g++?
Many thanks in advance for any help.