Pragma question
Sebastien.Wailliez@alcatel.be
Sebastien.Wailliez@alcatel.be
Tue Feb 20 07:57:00 GMT 2001
Hello,
Where can I find a precise description of the semantics of 'pragma pack' in GCC 2.95.2 ?
The output of the following code amazes me.
#include <stdint.h>
#include <iostream>
class withAttribute
{
uint16_t a;
uint32_t b;
}__attribute__ ((__packed__));
#define HANDLE_SYSV_PRAGMA
#pragma packed( 1 )
class withPragma
{
uint16_t a;
uint32_t b;
};
#pragma pack()
int main()
{
cout << "sizeof(withAttribute): " << sizeof(withAttribute)
<< ", sizeof(withPragma): " << sizeof(withPragma) << endl;
return 0;
}
I get: "sizeof(withAttribute): 6, sizeof(withPragma): 8"
Why is the structure padded even with pragma packed(1) ?
This annoys me a lot because there is no other way I can think of to ensure portability in the alignment of a structure.
Thanks for helping
S
ébastien E. Wailliez
More information about the Gcc-help
mailing list