Yul
February 9, 2006, 8:57pm
1
Hi guys,
Do any of you know how to set packing alignment to structure in GCC (or should I say compiling for Wismo Target)? I’m using OpenAT 3.01 and i’ve only recently discovered, #pragma pack(1) only works in Debug mode but does not work in Wismo Target.
Hence, a structure eg.
#pragma pack(1)
typedef struct
{
char FirstMember;
char SecondMember;
}Structure_T;
sizeof(Structure_T); would return 2 if packed into a single byte
BUT!!!
IT RETURNS 4 when compiled for Wismo Target.
So obviously it is packing into 4 byte lengths instead of 1. Does anyone know how to pack into a single byte length for Wismo Target?
Hi Yul,
I hardly found it too, this is a known problem with gcc.
You should write :
#pragma pack(1)
typedef struct
{
char FirstMember;
char SecondMember;
} __attribute__((__packed__)) Structure_T;
but only when compiled for Wismo Target
So I do:
#ifndef TARGET_GCC_COMPILER
#define ATTRIBUTE_PACKED
#else
#define ATTRIBUTE_PACKED __attribute__((__packed__))
#endif
and ATTRIBUTE_PACKED is used on each structure
Best regards,
tomalex
February 10, 2006, 3:34pm
3
Hello,
You can use “GNUC ” macro, it is automatically defined with GCC compiler.
tom
awneil
August 8, 2008, 7:29am
4
I’ve just been caught by this, too!
If it’s a “known problem with gcc”, is this documented somewhere? Do you have a link?
Any idea if there’s any plans to fix it?