Hi,
Searching for the web I found this two helpful links (for Visual Studio compiler):
http://msdn2.microsoft.com/en-us/lib...65(VS.80).aspx
http://msdn2.microsoft.com/en-us/lib...y1(VS.80).aspx
The second one works for me:
Qt Code:
#pragma pack(1) struct MB_Request { uchar function_code; quint16 start_adr; quint16 quantity_regs; }; #pragma pack(1) struct MBAP_Header { quint16 transaction_id; quint16 protocol_id; quint16 len; uchar unit_id; }; #pragma pack(1) struct MB_Message { MBAP_Header mb_hdr; MB_Request mb_req; };To copy to clipboard, switch view to plain text mode
Then, executing your example code, the structs are unaligned as I need for Modbus protocol.
Could I use "#ifndef" statment to know wich compiler is used to then use "#pragma pack(1)" or "__attribute__((packed))" depending on compiler?
So when I use GCC on GNU/Linux(or windows also) it will pack the data unaligned as expected. Could use GCC with Visual Studio?
Thanks,
Thanks,
Bookmarks