What does #pragma pack(0) do
-
Nope. Default size is NOT stating a #pragma pack, which defaults to DWORD, ie 4 byte alignment in structures. #pragma pack 0 means there is no packing between data members, so they are contiguous in memory. --edit-- Actually I am talking crap. pack (1) makes data member contiguous in memory, pack (0) resets packing. DOh!
============================== Nothing to say.
Erudite_Eric wrote:
pragma pack 0 means there is no packing between data members, so they are contiguous in memory.
no. that's pack(1) : align on single bytes. pack(n) specifies the structure alignment, not the number of bytes between structs.
-
I am reading 8 on my console.
-
The msdn says #pragma pack(n) will change current alignment value to n. But if n is zero, what will do?
-
The msdn says #pragma pack(n) will change current alignment value to n. But if n is zero, what will do?
-
#pragma pack(0)
#include
using namespace std;struct Test
{
char a;
int i;
};void main()
{
cout<I am using VS2008 SP1. The build is x86.
Now guess the result of sizeof(Test) ?? -
Why don't you continue reading
MSDN
?#pragma pack
documentation[^] states:Valid values are 1, 2, 4, 8, and 16.
Hence
0
is 'not valid' (I wouldn't try to make assumptions on a value marked as such).Veni, vidi, vici.
-
yu-jian wrote:
But if n is zero, what will do?
Add /WX to your compiler settings and recompile. You should pay more attention to compiler warnings. :) Best Wishes, -David Delaune
-
There is a error that Visual Studio 2008 only supports 1, 2, 4, 8... After add /WX to compiter.
See the documentation[^], which clearly states that the only valid values for
n
are 1, 2, 4, 8 and 16. Thus using 0 is an invalid#pragma
and will be ignored: the default packing (8) will be used.Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
-
Erudite_Eric wrote:
pragma pack 0 means there is no packing between data members, so they are contiguous in memory.
no. that's pack(1) : align on single bytes. pack(n) specifies the structure alignment, not the number of bytes between structs.
-
I am reading 8 on my console.
-
See the documentation[^], which clearly states that the only valid values for
n
are 1, 2, 4, 8 and 16. Thus using 0 is an invalid#pragma
and will be ignored: the default packing (8) will be used.Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
-
The msdn says #pragma pack(n) will change current alignment value to n. But if n is zero, what will do?
According to the C++ standard it can do whatever it likes. It's a way of implementors switching on non-standard features of the compiler. I think Griff and the others have told you enough about what it does on VC++ though! Cheers, Ash PS: Except this is the one thread Griff hasn't posted in. Let's try "Chris and the others..." instead!