public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Pragma question
@ 2001-02-20  7:57 Sebastien.Wailliez
  2001-02-20  9:15 ` Lewin A.R.W. Edwards
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastien.Wailliez @ 2001-02-20  7:57 UTC (permalink / raw)
  To: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 836 bytes --]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-02-20  9:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-20  7:57 Pragma question Sebastien.Wailliez
2001-02-20  9:15 ` Lewin A.R.W. Edwards

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).