From: Andrew Makhorin <mao@gnu.org>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: which gcc options can control layout of bit fields
Date: Wed, 27 Oct 2021 02:23:48 +0300 [thread overview]
Message-ID: <1635290628.10041.1.camel@gnu.org> (raw)
Hi,
Could anyone tell me which gcc options can control layout of bit
fields?
The problem I encountered is that gcc for Cygwin doesn't follow
System V ABI for i386. Namely, ABI says:
A bit-field must entirely reside in a storage unit appropriate for
its declared type. Thus a bit-field never crosses its unit boundary.
But in the code generated by gcc under Cygwin bit fields are allocated
contiguously and may cross the unit boundary. On the other hand, gcc
under Linux follows the ABI conventions.
Example:
struct { int a; char b; int c:14, d:14; int e; }
s = {0xAAAAAAAA, 0xBB, 0xCCC, 0xDDD, 0xEEEEEEEE};
static int *p = (int *)&s;
int main(void)
{
printf("0x%08X 0x%08X 0x%08X 0x%08X\n", p[0], p[1], p[2], p[3]);
return 0;
}
Under Cygwin s.d is splitted between p[1] and p[2]:
0xAAAAAAAA 0x774CCCBB 0x00000003 0xEEEEEEEE
Under Linux all is okay:
0xAAAAAAAA 0x000CCCBB 0x00000DDD 0xEEEEEEEE
Thank you,
Andrew Makhorin
next reply other threads:[~2021-10-26 23:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-26 23:23 Andrew Makhorin [this message]
2021-10-26 23:39 ` Jonathan Wakely
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=1635290628.10041.1.camel@gnu.org \
--to=mao@gnu.org \
--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).