Hi,
Have you placed __declspec before MBAP_Header too?
Yes:
//#pragma pack(1)
__declspec(align(1)) struct MB_Request
{
uchar function_code;
quint16 start_adr;
quint16 quantity_regs;
};
//#pragma pack(1)
__declspec(align(1)) struct MBAP_Header
{
quint16 transaction_id;
quint16 protocol_id;
quint16 len;
uchar unit_id;
};
//#pragma pack(1)
__declspec(align(1)) struct MB_Message
{
MBAP_Header mb_hdr;
MB_Request mb_req;
};
//#pragma pack(1)
__declspec(align(1)) struct MB_Request
{
uchar function_code;
quint16 start_adr;
quint16 quantity_regs;
};
//#pragma pack(1)
__declspec(align(1)) struct MBAP_Header
{
quint16 transaction_id;
quint16 protocol_id;
quint16 len;
uchar unit_id;
};
//#pragma pack(1)
__declspec(align(1)) struct MB_Message
{
MBAP_Header mb_hdr;
MB_Request mb_req;
};
To copy to clipboard, switch view to plain text mode
But
int iA1 = __alignof(MBAP_Header);
int iA2 = __alignof(MB_Request);
int iA3 = __alignof(MB_Message);
int iA1 = __alignof(MBAP_Header);
int iA2 = __alignof(MB_Request);
int iA3 = __alignof(MB_Message);
To copy to clipboard, switch view to plain text mode
Returns always "2" for iA1, iA2 and iA3.
Don't worry about it, using "#pragma pack(1)" is going well.
Thanks for your time and your knowdelege.
Bookmarks