This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Pragma question
- To: gcc-help at gcc dot gnu dot org
- Subject: Pragma question
- From: Sebastien dot Wailliez at alcatel dot be
- Date: Tue, 20 Feb 2001 16:56:18 +0100
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