Click here to Skip to main content
16,011,374 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Question about #pragma pack(1) Pin
Rick York5-Jul-03 22:03
mveRick York5-Jul-03 22:03 
GeneralRe: Question about #pragma pack(1) Pin
George25-Jul-03 22:12
George25-Jul-03 22:12 
GeneralRe: Question about #pragma pack(1) Pin
peterchen5-Jul-03 22:18
peterchen5-Jul-03 22:18 
GeneralRe: Question about #pragma pack(1) Pin
peterchen5-Jul-03 22:16
peterchen5-Jul-03 22:16 
GeneralRe: Question about #pragma pack(1) Pin
George26-Jul-03 17:10
George26-Jul-03 17:10 
GeneralRe: Question about #pragma pack(1) Pin
peterchen6-Jul-03 21:36
peterchen6-Jul-03 21:36 
GeneralRe: Question about #pragma pack(1) Pin
George26-Jul-03 21:57
George26-Jul-03 21:57 
GeneralRe: Question about #pragma pack(1) Pin
peterchen6-Jul-03 22:26
peterchen6-Jul-03 22:26 
1) it's "implementation defined". The standard gurantees only that, in above example, y goes after x, a after y, etc.
This is because the compiler is supposed to optimize this for the target platform. (I.e. if you have a target platform with no alignment rules at all, no padding would happen).
But all compilers for the Intel platform support alignment in a similar way, usually through custom compiler options. And compilers for other platforms will likely have something similar.


2)

try it Wink | ;)

struct foo {
  int x, y; char a, b;
};
struct bar {
  double x; char a, b;
};

void main()
{
  cout << "sizeof(foo) = " << sizeof(foo) << endl;
  cout << "sizeof(bar) = " << sizeof(bar) << endl;
}


the packing is always determined by both the "pack value" and the struct members involved (I guess it gets really tricky when you combine structs Wink | ;)

The idea is if you build an array of foo's
foo arr_foo[10]
the "double" at arr_foo[1] should be aligned by a multiple of 8, hence the structure size must be a multiple of 8.
for
bar arr_bar[10]
the "int" at arr_1 should be aligned by a multiple of 4, so the structure size needs to be a multiple of 4.

The pack value only indicates the maximum padding (the max number of pad bytes is packvalue-1)



"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS

sighist | Agile Programming | doxygen

GeneralRe: Question about #pragma pack(1) Pin
George26-Jul-03 22:51
George26-Jul-03 22:51 
GeneralRe: Question about #pragma pack(1) Pin
peterchen7-Jul-03 1:15
peterchen7-Jul-03 1:15 
GeneralHexadecimal representation Pin
punkms15-Jul-03 20:46
punkms15-Jul-03 20:46 
GeneralRe: Hexadecimal representation Pin
Rick York5-Jul-03 21:31
mveRick York5-Jul-03 21:31 
GeneralRe: Hexadecimal representation Pin
Ryan Binns5-Jul-03 22:05
Ryan Binns5-Jul-03 22:05 
GeneralRe: Hexadecimal representation Pin
peterchen5-Jul-03 22:21
peterchen5-Jul-03 22:21 
GeneralRe: Hexadecimal representation Pin
Ryan Binns5-Jul-03 22:31
Ryan Binns5-Jul-03 22:31 
GeneralRe: Hexadecimal representation Pin
peterchen6-Jul-03 21:41
peterchen6-Jul-03 21:41 
GeneralRe: Hexadecimal representation Pin
Ryan Binns6-Jul-03 22:27
Ryan Binns6-Jul-03 22:27 
GeneralRe: Hexadecimal representation Pin
Rick York5-Jul-03 22:32
mveRick York5-Jul-03 22:32 
GeneralRe: Hexadecimal representation Pin
peterchen5-Jul-03 21:42
peterchen5-Jul-03 21:42 
GeneralRe: Hexadecimal representation Pin
punkms15-Jul-03 22:04
punkms15-Jul-03 22:04 
GeneralRe: Hexadecimal representation Pin
peterchen5-Jul-03 22:32
peterchen5-Jul-03 22:32 
GeneralPersisting MFC dialog's object properties Pin
haritadala5-Jul-03 18:40
haritadala5-Jul-03 18:40 
GeneralRe: Persisting MFC dialog's object properties Pin
Ryan Binns5-Jul-03 20:22
Ryan Binns5-Jul-03 20:22 
GeneralRe: Persisting MFC dialog's object properties Pin
Rage6-Jul-03 21:01
professionalRage6-Jul-03 21:01 
GeneralRe: Persisting MFC dialog's object properties Pin
Ryan Binns6-Jul-03 22:24
Ryan Binns6-Jul-03 22:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.