From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: john smith <wempwer@gmail.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: are statically allocated structs always aligned to a machine word on x86/x86_64?
Date: Fri, 21 Aug 2015 18:49:00 -0000 [thread overview]
Message-ID: <CAH6eHdQdAt1sqtnZe7CiJtWKb_SeggnXieiiR7Wf4D8Uf1sLyg@mail.gmail.com> (raw)
In-Reply-To: <CAKmQUfZT04z8pd9bvqazEPkV1iqRrUxw82nxd3RbOerVbyxqhA@mail.gmail.com>
On 21 August 2015 at 19:39, john smith wrote:
> I didn't find any information about alignment requirements for
> statically allocated objects in GCC and x86-64 manual (or I have
> missed because the manual is huge). I noted that sometimes variables
> such as int are not aligned on word boundary in x86 and x86_64 but I
> have never seen a struct that wouldn't be allocated at address that
> isn't a multiple or 4/8.
Three of these structs are not word-aligned:
#include <stdio.h>
struct A { char c; };
struct A a[4];
int main()
{
for (int i=0; i<4; ++i)
printf("%p\n", a+i);
}
> I am asking this question because I would
> like to know whether it's safe to assume that struct will be always
> assigned at a word boundary and therefore it's possible to correctly
> calculate a struct size without running a program.
sizeof?
next prev parent reply other threads:[~2015-08-21 18:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-21 18:39 john smith
2015-08-21 18:49 ` Jonathan Wakely [this message]
2015-08-21 19:31 ` john smith
2015-08-22 23:16 ` Jonathan Wakely
2015-08-23 11:05 ` Segher Boessenkool
2015-08-23 13:49 ` Jonathan Wakely
2015-08-23 13:52 ` Jonathan Wakely
2015-08-23 15:19 ` Segher Boessenkool
2015-08-23 15:23 ` 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=CAH6eHdQdAt1sqtnZe7CiJtWKb_SeggnXieiiR7Wf4D8Uf1sLyg@mail.gmail.com \
--to=jwakely.gcc@gmail.com \
--cc=gcc-help@gcc.gnu.org \
--cc=wempwer@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).