public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Matthew Bloch <mattbee@soup-kitchen.net>
To: Andrew Lees <andrewl@acay.com.au>
Cc: gcc-help@gcc.gnu.org
Subject: Re: struct packing reliability?
Date: Wed, 27 Feb 2002 04:18:00 -0000	[thread overview]
Message-ID: <20020227114216.3028.qmail@stoneboat.bytemark.co.uk> (raw)
In-Reply-To: <20020227023530.31397.qmail@stoneboat.bytemark.co.uk>

On Wednesday 27 February 2002 4:19 am, Andrew Lees wrote:
> Hi,
>
> I'm not sure this will help, but have you tried
>
> #pragma pack(1)

Yes, same results as when I use the __attribute__ qualifier.

Unless there's something I'm missing, I think it's impossible to pack 
structs-within-structs on bit boundaries, as this test case demonstrates:

------------------------------------------------------------------------
#pragma pack(1)

struct test1
{
   int a : 5;
   struct {
      int b1 : 3;
      int b2 : 2;
   } b;
   int c : 5;
   int d : 1;
};

struct test2
{
   int a : 5;
   int b : 5;
   int c : 5;
   int d : 1;
};

int main(void)
{
   printf("%d %d\n", sizeof(struct test1), sizeof(struct test2));
   /* prints '3 2', annoyingly */
}
 
#pragma pack()
------------------------------------------------------------------------

The non-portability aspect isn't a major concern for me, given that this is 
for a fixed hardware platform and fixed compiler, but it's a shame that I 
can't get the behaviour I'm after because it makes use of these structures 
that little bit uglier.

Unless anybody knows better...?

-- 
Matthew       > http://www.soup-kitchen.net/
              > ICQ 19482073

  reply	other threads:[~2002-02-27 11:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-26 18:38 Matthew Bloch
2002-02-27  4:18 ` Matthew Bloch [this message]
2002-02-28 15:55 ` Andrew Lees
2002-02-28 15:55 ` Andrew Lees

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020227114216.3028.qmail@stoneboat.bytemark.co.uk \
    --to=mattbee@soup-kitchen.net \
    --cc=andrewl@acay.com.au \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).