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:
  1. #pragma pack(1)
  2. struct MB_Request
  3. {
  4. uchar function_code;
  5. quint16 start_adr;
  6. quint16 quantity_regs;
  7. };
  8.  
  9. #pragma pack(1)
  10. struct MBAP_Header
  11. {
  12. quint16 transaction_id;
  13. quint16 protocol_id;
  14. quint16 len;
  15. uchar unit_id;
  16. };
  17.  
  18. #pragma pack(1)
  19. struct MB_Message
  20. {
  21. MBAP_Header mb_hdr;
  22. MB_Request mb_req;
  23. };
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,