What is the difference between
pragma pack(n)andpragma pack(push,n)#pragma pack(pop)and#pragma pack()
Can someone explain through an example ? Which should be used when ?
I went through https://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Structure_002dPacking-Pragmas.html#:~:text=%23pragma%20pack(push%5B%2C,and%20removes%20that%20stack%20entry) already but looking out for more explanation.
If you use
pushandpop, you can "stack" multiple packing specifications. Without, you can just return to the default:The result talks for itself:
You can use
pushandpopall the time. Especially you can#includeheaders with these directives without fear of breaking other pack adjustments.This is the relevant part of the documentation:
Unfortunately the maximum number of pushes is not documented. However, in practice you will not reach it.