what this line do in the MSVC++:
#pragma pack (push, 1)
#pragma pack
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: #pragma pack
Hi,
#pragma is used to provide compiler specific actions , usually used as #pragma string
if string is applicable to a particular compiler then it is executed , else ignored.
#pragma pack(push ,1 ) , I think has something do with structure or union alignment , I guess it sets the alignment value to 1 .
There is an option in mingw to even link to a library without using compiler options (it is not recommended though) , i do not remember how.
< Its just a guess , do not heavily rely on my info >
Regards
Sandeep
#pragma is used to provide compiler specific actions , usually used as #pragma string
if string is applicable to a particular compiler then it is executed , else ignored.
#pragma pack(push ,1 ) , I think has something do with structure or union alignment , I guess it sets the alignment value to 1 .
There is an option in mingw to even link to a library without using compiler options (it is not recommended though) , i do not remember how.
< Its just a guess , do not heavily rely on my info >
Regards
Sandeep
Re: #pragma pack
That command in MSVC packs structures so that there are no alignment gaps between structure fields.
Assume you had, for example, a structure with two bytes and a short. Then theoretically, the compiler might stick two empty bytes after the first two bytes, and align the short on a 4 byte boundary, or something. The #pragma prevents that.
Assume you had, for example, a structure with two bytes and a short. Then theoretically, the compiler might stick two empty bytes after the first two bytes, and align the short on a 4 byte boundary, or something. The #pragma prevents that.
Re: #pragma pack
Code: Select all
struct Bla
{
char x;
short y;
char z;
};