Yeah, I'm slownly working toward a solution to the problem, yet some stuff should still find an issue : 1- #pragma pack(8) align on a 8-byte boundary members of size >= 8, it doesn't add padding byte (what is in fact not a problem) 2- #pragma pack(1) align on a 1-byte boundary every members, nice for sending/receiving the struct as a frame. However that show the problem of software alignment fault on FPU members (float, double) and members whose size is greater than the current architechture word 3- #pragma pack(2) might lift up the problem upon most cases, but FPU members still get troubles 4- anonymous union is a nice stuff, yet I not always own the headers. Understand I work with compiled third party libraries and their header file. I work with struct coming out from these header files, and while I need the native format to deal with the library, I'd like to use the struct definition as a skeleton for my message's declaration as well. I 'just' need to enforce that the format of my message will be both 32 and 64 bit compatible (best is packing on 2 with 64 bits pointer).
#include <>
/* ======== foreign_lib.h ========
typedef struct foreign_struct
{ char nMode;
float fValue;
int* pArray;
};
foreign_struct* get_struct(void);
=== I HAVE NO CONTROL OVER THIS === */
// int send_frame(void* pBuffer, size_t nSize);
int test_struct(foreign_struct* frame)
{
#pragma pack(2)
struct foreign_struct sFrame;
#pragma pack()
// foreign_struct : native struct format
// sFrame : my packed struct frame
if(send_frame(frame, sizeof(foreign_struct))
== send_frame(&sFrame, sizeof(sFrame)))
return (int) TRUE;
else
return (int) FALSE;
}
int main(int argc, char *argv[])
{
return test_struct(get_struct());
}
But thanks for you offer, good stuff to know ! Kochise
In Code we trust !