c++pragma-pack

What is `#pragma pack` for in network programming?


 #pragma pack(push)
 #pragma pack(1)

I downloaded a tutorial and it has these lines in the header file. I will appreciate if you guys can provide me any tutorials or references related to this.


Solution

  • Microsoft's explanation:

    http://msdn.microsoft.com/en-us/library/aa273913(v=vs.60).aspx

    IBM's AIX xlC explanation:

    http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Fcompiler%2Fref%2Frnpgpack.htm

    Basically, it determines the byte boundaries that will be used when storing a structure or union. The push/pop acts as a way to store and retrieve these settings on a stack.

    For future reference, you might save yourself some time by searching for the keywords you're asking as about on the web. All I did to find this information was search for "pragma pack" at http://www.google.com