public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "emmiller at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug objc/50909] Process "#pragma options align=reset" correctly on Mac OS X
Date: Mon, 25 Oct 2021 11:01:35 +0000	[thread overview]
Message-ID: <bug-50909-4-bf85x2vozK@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-50909-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50909

Evan Miller <emmiller at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |emmiller at gmail dot com

--- Comment #16 from Evan Miller <emmiller at gmail dot com> ---
An unusual but viable workaround for this problem is:

  #pragma options align=power
  #pragma options align=power
  #pragma options align=power
  #pragma options align=power
  #pragma options align=power
  #include <IOKit/usb/USB.h>

This technique pre-loads the "options" alignment stack with five default
values. When

  #pragma pack(1)

is encountered in the header file, the global alignment is set to 1 byte. Then
when

  #pragma options align=reset

is encountered, a value is popped off the options stack and the global
alignment is set to the value at the top of the stack ("power" which is
implemented as the platform default). So the pack and options pragmas inside
the header file end up having the desired effect.

If the number of "align=power" pragmas before the header inclusion equals the
number of "align=reset" pragmas inside the header, then after inclusion, the
alignment stack will be whatever it was before all the "align=power" pragmas.
It probably won't hurt anything to have extra values on the alignment stack, so
you can add a few more to be safe.

      parent reply	other threads:[~2021-10-25 11:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-29  5:03 [Bug objc/50909] New: " carsomyr at gmail dot com
2012-05-23 21:35 ` [Bug objc/50909] " carl at lytro dot com
2012-08-08  8:26 ` roman at qubyx dot com
2013-09-13 18:53 ` dc7000 at att dot com
2013-09-13 19:05 ` dominiq at lps dot ens.fr
2013-09-13 20:32 ` dc7000 at att dot com
2014-06-23 14:52 ` dominiq at lps dot ens.fr
2014-06-23 15:48 ` alex.wolf at gmail dot com
2014-06-23 16:30 ` manu at gcc dot gnu.org
2021-10-25 11:01 ` emmiller at gmail dot com [this message]

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=bug-50909-4-bf85x2vozK@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).