From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Erick Ochoa <erick.ochoa@theobroma-systems.com>
Cc: "Richard Biener" <richard.guenther@gmail.com>,
"gcc@gcc.gnu.org" <gcc@gcc.gnu.org>,
"Christoph Müllner" <christoph.muellner@theobroma-systems.com>,
"Dr. Philipp Tomsich" <philipp.tomsich@theobroma-systems.com>
Subject: Re: Question about sizeof after struct change
Date: Mon, 06 Jan 2020 11:03:00 -0000 [thread overview]
Message-ID: <CAH6eHdQo0RzGo9iL6UpJPAHPeS-0Sw0zyR3oxRxJuCS7z9zhHQ@mail.gmail.com> (raw)
In-Reply-To: <1d686046-16b9-f8a6-178e-4bff501aaef2@theobroma-systems.com>
On Fri, 3 Jan 2020 at 16:09, Erick Ochoa wrote:
> Do you mean something like taking the address of a struct and adding an offset
> to access a field?
Yes, the following code is valid:
struct S { int unused; int used; };
static_assert( sizeof(S) == 8 );
S s[4];
int* s2_used = (int*)((char*)s + 20);
Accessing the field doesn't refer to S::used or S::unused directly,
and doesn't use sizeof(S) or sizeof(int) explicitly.
So if your pass removes S::unused, then you'd need to analyse
((char*)s + 20) to determine that it accesses s[2].used and then
adjust it to ((char*)s + 8) instead.
next prev parent reply other threads:[~2020-01-06 11:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-23 17:30 Erick Ochoa
2019-12-24 7:37 ` Richard Biener
2020-01-03 16:09 ` Erick Ochoa
2020-01-06 11:03 ` Jonathan Wakely [this message]
2020-01-07 12:43 ` Richard Biener
2019-12-28 21:13 ` Nathan Sidwell
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=CAH6eHdQo0RzGo9iL6UpJPAHPeS-0Sw0zyR3oxRxJuCS7z9zhHQ@mail.gmail.com \
--to=jwakely.gcc@gmail.com \
--cc=christoph.muellner@theobroma-systems.com \
--cc=erick.ochoa@theobroma-systems.com \
--cc=gcc@gcc.gnu.org \
--cc=philipp.tomsich@theobroma-systems.com \
--cc=richard.guenther@gmail.com \
/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).