public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bo Thorsen <bo@sonofthor.dk>
To: Dennis Bjorklund <db@zigo.dhs.org>
Cc: <gcc@gcc.gnu.org>
Subject: Re: packed, aligned
Date: Sun, 11 Feb 2001 02:39:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.31.0102111122170.592-100000@pluto.sonofthor.dk> (raw)
In-Reply-To: <Pine.LNX.4.30.0102111029440.6140-100000@merlin.zigo.dhs.org>

On Sun, 11 Feb 2001, Dennis Bjorklund wrote:
> I'm very interested to know why one have choosen to not force the packed
> struct to be of minimal size.

For a struct like this:

struct bad_struct
{
  char c1;
  char *cp1;
  char c2;
  char *cp2;
};

on an architecture where pointers must be 4-byte aligned (I think sparc is
one such architecture) can not be packed. You could organize these
yourself like { *cp1, *cp2, c1, c2 } but doing that optimally by the
compiler is an NP-complete problem. Not to mention that some non-portable
applications could be depending on knowing the layout of the struct. If
someone would access these by offsets to the base pointer of the struct,
this would break. And even though I would probably consider this stupid,
it's perfectly legal and just because I can't see any use of it does not
mean there can't be a good reason for doing so.

Bottom line: This is a problem that no compiler will ever be able to
solve. It is a perfect example of the fact that compilers can never be so
good that they will just do what you want, and not what you told them to.
You have to be responsible for your own code and arrange the structs so
they can be packed. Yes, that sucks, but there's nothing you can do.

Bo.

-- 

     Bo Thorsen                 |   Lahnsgade 31, st.
     Free software developer    |   5000 Odense C
     SuSE Labs                  |   Denmark

  reply	other threads:[~2001-02-11  2:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-11  1:44 Dennis Bjorklund
2001-02-11  2:39 ` Bo Thorsen [this message]
2001-02-11  3:22   ` Fergus Henderson
2001-02-11  3:21 ` Graham Murray
2001-02-11 11:15 ` Richard Henderson
2001-02-11  4:55 dewar
2001-02-11  4:57 dewar
2001-02-13 14:29 Richard Kenner
2001-02-13 17:39 Mike Stump

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=Pine.LNX.4.31.0102111122170.592-100000@pluto.sonofthor.dk \
    --to=bo@sonofthor.dk \
    --cc=db@zigo.dhs.org \
    --cc=gcc@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).