From: Martin York <martin.york@veritas.com>
To: gcc-help@gcc.gnu.org
Subject: RE: struct and members addresses
Date: Thu, 24 Apr 2003 12:58:00 -0000 [thread overview]
Message-ID: <8BE017CC8923D511A00A0008C78605EE051B0F63@lmoxch04.enterprise.veritas.com> (raw)
Just to throw a spanner in the works!
Assuming C only
What happens if there are more members of the structure.
Is the compiler allowed to reorder the members of the
structure for efficiency in memory layout?
-----Original Message-----
From: Alexandre Courbot [mailto:Alexandre.Courbot@lifl.fr]
Sent: 24 April 2003 07:16
To: Cédric Lucantis; gcc-help@gcc.gnu.org
Subject: Re: struct and members addresses
> struct foo
> {
> any_type first_member;
> };
>
> struct foo my_struct;
>
> void * addr1 = &my_struct;
> void * addr2 = &my_struct.first_member;
>
> /* ----------------------------------*/
>
> can I be sure that `addr1' will be equal to `addr2' ?
In C, I think you can safely. In C++, if your struct has virtual methods,
the
adress won't be the same since I think GCC puts the vtable at the beginning
of the struct. But as long as you don't use virtuals, it should be ok AFAIK.
Alex.
next reply other threads:[~2003-04-24 12:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-24 12:58 Martin York [this message]
[not found] <616BE6A276E3714788D2AC35C40CD18DC3E972@whale.softwire.co.uk>
2003-04-24 13:25 ` Rupert Wood
-- strict thread matches above, loose matches on Subject: below --
2003-04-24 11:18 Agust Karlsson
2003-04-24 11:01 Cédric Lucantis
2003-04-24 11:15 ` Alexandre Courbot
2003-04-24 11:29 ` Andrea 'fwyzard' Bocci
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=8BE017CC8923D511A00A0008C78605EE051B0F63@lmoxch04.enterprise.veritas.com \
--to=martin.york@veritas.com \
--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).