This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Pragma question




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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]