Click to See Complete Forum and Search --> : Network: How do I transfer structure? or How do I impose a packet scheme?


miteshpandey
December 11th, 2004, 11:30 AM
The following question is asked in regard to the following FAQ (http://www.codeguru.com/forum/showthread.php?t=306399)...


Thank you very much. This may indeed help me.

NOTE: Another thing you have to keep in mind while dealing with structures is that sizeof may report a size different from the actual size of all the elements of the structure. This is due to the structure alignment done by the compiler for optimization. You can work around this by using the #pragma pack(1)...#pragma pack() compiler directive.


I have one question;

If I don't use the #pragma pack(1)...#pragma pack() directive for my structure will something go wrong?

Mathew Joy
December 14th, 2004, 12:53 PM
There is an faq (http://www.codeguru.com/forum/showthread.php?s=&threadid=276622) discussing about the thing.

It is not about what will go wrong. It is about what may go wrong. As long as you are using 'sizeof' to get the size of the struct and the receiving app is complied on the same machine architecture with the same compiler and options, it is OK. Otherwise you have no guarantee that the other machine will receive data properly.