This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Data alignment with gcc


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]