all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Packing of union fields and bool_bf
Date: Sat, 13 Oct 2018 09:58:00 -0600	[thread overview]
Message-ID: <87h8hpbzzr.fsf@tromey.com> (raw)
In-Reply-To: <838t31vpwy.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 13 Oct 2018 18:15:25 +0300")

>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:

Eli> While working on bug#33017, I found out something unexpected: using
Eli> bool_bf in union members bloats the union.
...
Eli> Note the difference between handling 'unsigned int' fields and
Eli> 'bool_bf' fields: the former are nicely packed, whereas the latter are
Eli> not.  Which causes the size of union to be 12 bytes, instead of the
Eli> expected 4.  The 'bool' type is 1-byte wide on this platform.

Eli> Is this expected?  Should we continue using bool_bf in these cases?

I think the MS ABI has special rules about packing bit fields.
From https://docs.microsoft.com/en-us/cpp/c-language/padding-and-alignment-of-structure-members?view=vs-2017:

    Adjacent bit fields are packed into the same 1-, 2-, or 4-byte
    allocation unit if the integral types are the same size and if the next
    bit field fits into the current allocation unit without crossing the
    boundary imposed by the common alignment requirements of the bit fields.

So in this case, I think if the underlying type of bool_bf is "unsigned int",
then it will continue to pack as expected.

Tom



  reply	other threads:[~2018-10-13 15:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-13 15:15 Packing of union fields and bool_bf Eli Zaretskii
2018-10-13 15:58 ` Tom Tromey [this message]
2018-10-13 16:22   ` Paul Eggert
2018-10-13 16:54     ` Eli Zaretskii
2018-10-13 16:43   ` Eli Zaretskii

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=87h8hpbzzr.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.